If you need to allocate a TEST object dynamically then you can do this:
int main(int argc, char * argv[])
{
//Just to fill an array with some integers
int rows = 3;
int cols = 3;
TEST* t = new TEST;
t->row = rows;
t->col = cols;
t->a = new int*[rows];
for(int i = 0; i < rows; i++)
t->a[i] = new int[cols];
srand(time(NULL));
for (int x = 0; x < rows; x++){
for (int y = 0; y < cols; y++){
t->a[x][y] = rand() % 10 + 1;
}
}
return 0;
}
2
solved Passing a two-dimensional array to a struct (C++)