2D dynamic array

I want to add the handle of a 2D dynamic array to my base class so I can randomize this array in the base class for all extended classes, but in the base class I do not know the length of array. I just know that I need an array of bit-vectors.

Base class:

  rand bit data[][];

In extended class:

    data = new[32];
    foreach (data[i])
      data[i] = new[20];

In the extended class I expected an array with 32 elements and each element with 20 bit.
Instead it created an array with 32 subarrays and each of this subarray is an array of 20 1 bit elements. Is it possible to get what I wanted or is it necessary to know the bit length in the base class?

The use of the term “bit-vectors” implies you want dynamic unpacked array of a packed array. SystemVerilog does not have dynamically sized packed arrays.

I’m assuming you want bit-vectors because you’re planning to do some integral operation on the elements. In that case the easiest solution might be to declare them with the largest length/width needed.