Using the string I provided in the create function

Hi

I have an array of class:

a a_ins[3];

I also have array of strings, in order to give each handle of ‘a’ a unique name:

a_stri = {“Aaron”, “Benji”, “Calvin”};

I use the create function.

foreach (a_ins[i])
a_ins[i] = a::type_id::create(a_stri[i],this);

now- I want to use the handle, with the unique name I gave in the build_phase, so instead of just a string, it will be the handle itself.
I mean- instead of useing

a_ins[0].bla_bla();

I’ll use

Aaron.bla_bla(();

.

is there a way to do it?

Thanks!

Looks a little bit complicated what you are doing. You should use an associative array. This allows strings as index. This would make your solution very easy.
I do not understand why you are initialising your arrays in the build_phase. This is a decicated phase for all uvm_components which build the topology of the UVM testbench. You can make the assigments in the run_phase.

You cannot create variable names from strings. Use an associve array instead of a fixed size array;

a a_ins[string];
foreach (a_stri[i])
     a_ins[a_stri[i]] = a::type_id::create(a_stri[i],this);
...
a_inst["Arron"].bla_bla();