Multi-dimensional Array Initialization [C++] (25)

7 Name: #!/usr/bin/anonymous : 2007-10-31 00:40 ID:M740Z140

>>6

x = prMatrix[y]->[z] is never valid syntax. Array lookups are only ever done with [], no matter if you're dealing with pointers or arrays. Syntactically, arrays and pointers are nearly indistinguishable.

Anyway, >>1, what you want to do is something along the lines of (skipping all the class syntax):

double **array;
array=new (double *)[rows];
for(int i=0;i<rows;i++) array[i]=new double[cols];

Then you can address it as array[row][col]. Remember to loop through it and free all the sub-arrays when you free the whole thing!

If you want it a bit more efficient, allocate a buffer of rows*cols and just put pointers to various offsets into that buffer into array.

This thread has been closed. You cannot post in this thread any longer.