I'm trying to create an array of handles for a class, by randomize function I'll get the "no of transcations", this determines the no of handles to be created.class_name obj_name[transactions]; is this right?

I’m trying to create an array of handles for a class, by randomize function I’ll get the “no of transactions”, this determines the no of handles to be created. for example : class_name obj_name[transactions]; is this right?

coz I’m getting a syntax error when I do this

In reply to Ammu4392:

Can you please show some code, including the declarations of any variables reference by that code, and the actual error message.

In reply to Ammu4392:

I believe you want something like…

classA obj[]; // dynamic array
...

virtual task body();
  a.randomize();
  num_txns = a.transactions;
  obj=new[num_txns];
  ...

In reply to dave_59:

virtual task body();
	     a.randomize();
	    txns = a.transactions; 
	   classA obj[txns];
 for(int i=0; i<txns; i=i+1)begin
	    `ovm_create(obj[ i])
             a.randomize();
	     int x = a.core;
	    `ovm_send(obj[i])
	      wait(obj.rsp != null );
          end   
	endtask : body

In reply to bmorris:

Yes. But does soemthing like that works?

In reply to Ammu4392:

Can u also tel me how I’ll iterate through the array??
shud i use for loop or foreach?

In reply to Ammu4392:

I’d use foreach for an array, but you can use both.

foreach (obj[i]) begin

end

In reply to bmorris:

Can u tel me why we are declaring the obj declaration outside of body?