class cls;
rand integer Var;
endclass
class q_cls;
rand cls obj[$];
rand bit [2:0] length;
function void pre_randomize();
length = $urandom % 20 ; // Compute the length of queue.
obj = {} ; // Delet all the elements in the queue or .delet can be used
repeat(length)
begin
cls obj_loc;
obj_loc = new(); // Creat new object.
obj.push_back(obj_loc) ; // insert it into queue.
end
endfunction
endclass
program q_obj_p_93;
q_cls obj1= new();
initial
begin
if(obj1.randomize())
begin
$display( "Randomization done");
$write( " Length of q : %0d :::",obj1.length);
for(int i ;i< obj1.length;i++)
begin
cls obj_temp;
obj_temp=new();
obj_temp = obj1.obj.pop_front();
$write(" : %0d : ",obj_temp.Var);
end
end
else
$display( "Randomization failed");
end
endprogram
The object at dereference depth 0 is being used before it was
constructed/allocated.
Please make sure that the object is allocated before using it.
#0 in unnamed$$_5 at testbench.sv:37
#1 in q_obj_p_93
please can anyone rectify the above code