7.10.2.2 Insert()
The prototype of the insert() method is as follows:
function void insert(input int index, input element_t item);
The insert() method inserts the given item at the specified index position.
The second argument to the insert method is expecting an element type, not an array type. (Unless you have a multidimensional queue of arrays, of course).
You are getting an error message because you are trying to pass a queue (an unpacked array of ints) to an int (a packed array of bits).
In reply to Have_A_Doubt:
I think its confusing because the code you posted should not have worked. (But does in a few implementations)
It is helpful to think of SystemVerilog having arrays of arrays instead gf multi-dimensional arrays. That means you have to create an element for each queue dimension before you can start adding elements to the next dimension. That means your code should have been written as
for ( int i1 = 0 ; i1 < 2; i1++ ) begin
q2.insert(i1,{}); // equivalent to q2.push_back({}) in this example
for ( int i2 = 0 ; i2 < 4; i2++ ) begin
q2[i1].insert(i2,(i1+i2*10)); // q2[i1].push_back(i1+i2*1)
end
end
Now adding more dimensions is straightforward.
module top;
int q3[$][$][$];
initial begin
for ( int i1 = 0 ; i1 < 2; i1++ ) begin
q3.push_back( {} );
for ( int i2 = 0 ; i2 < 4; i2++ ) begin
q3[i1].push_back( {} );
for ( int i3 = 0 ; i3 < 6; i3++ ) begin
q3[i1][i2].push_back( i1+i2*10+i3*100 );
end
end
end
$display("%p",q3);
end
endmodule