hi. i am wanting to know how to make a 2d dynamic array.

if i typically compiled :

int row = 2;
int column = 3;

int a[row][column];

That would cause an error in comilation saying non constant array bounds


But, for the 1D case,I can overocme this by :

int * ptr = NULL;
int row;
cin >> row;
ptr = new int[row];

That will create a dynamic array where ptr points to the first element/


But when I try this for the 2D case, it doesnt work. THe prototype for the 2D case would be:

int row;
int column;
int * ptr = NULL;
cin >> row;
cin >> column;
ptr = new int[row][column];


This would be the prototype ; i.e. for other datatypoes i just switch int with what i want.



In my case, I have a custom datatype:

class Pixel
{
char r;
char g;
char b;;
}

I then got rows and columns into variable unsigned integer rows, and unsigned integer columns

Then I created:

Pixel * ptr = NULL;

This works: ptr = new Pixel[rows] ;



But this does not work: ptr = new Pixel[rows][columns]; visual c++ gives :

error C2540: non-constant expression as array bound

and

error C2440: 'initializing' : cannot convert from 'Pixel (*)[1]' to 'Pixel *'




HEPL PLEASE