I've modified a code block written by dave_59 in this answer to create a pathological case that illustrates my question:
virtual class base;
???
endclass
class my_class#(int width) extends base;
typedef bit [width-1:0] vec_t;
virtual function vec_t get_zeros();
vec_t x = '0;
return x;
endfunction
endclass
base my_array [1:3];
initial begin
my_array[1] = my_class#(1)::new;
my_array[2] = my_class#(2)::new;
my_array[3] = my_class#(3)::new;
...
Is there a way to do the above in a loop? Something like this is what I want, although it doesn't work because SV requires class parameters to be statically defined:
for (int i=1; i<=3; i++)
my_array[i] = my_class#(i)::new;
I would think a generate block would work, but I'm having trouble figuring out syntax that compiles. I'm also not sure what needs to be in the base class (or if I even need a base class). If I do need a base class, I'm also not clear how it should handle the get_zeros
function since that function's return type depends on the parameter.