-
dynamic allocation.
How do I declare multi dimensional arrays?
Code:
char *ptr;
ptr = new char[size];
Worked... but...
Code:
char **ptr;
ptr = new char[3][2];
Gives an error 'Cannot convert char[2]* to char **'.
Code:
char * ptr[];
ptr = new char [2][3];
Obviuosly gave an error 'The size of ptr[] is unknown or zero.'
I tried some other combinations in vain; but they gave errors like 'Lvalue required'.
I checked many books, but they only give the syntax for single dimensional arrays...
Please Excuse if this question looks really stupid or if the answer is obvious...
-
This only works if you know the sizes of your minor dimensions at compile time
char (*ptr)[2];
ptr = new char[3][2];
-
you do nopt make a 2d array dynamically like that in c++. There is no operator new[][].
You will need to use a couple of loops. It has been covered many times. Search the boards to find code samples.
-
Boy, now this's quick reply.
I wanted to declare an array to store the data in a 'raw' file.
since I don't know the the dimensions of the file forehand, I asked this question...