I've seen how to dynamically allocate a two-dimensional array row by row. But why couldn't you just simply allocate the memory and cast it into a 2D array, like this:
I guess it's not technically an array of an array, but the result will achieve that effect. Also, this would be handy:Code:// I want a dynamically allocated int[2][2], so allocate enough memory: int* buffer = new int [2 * 2]; // And do the cast: int (*p_array) [2] [2] = (int (*) [2] [2]) buffer; // ... delete [] buffer; // Or, delete [] p_array; ?
Code:int (&the_array) [2] [2] = *p_array;



LinkBack URL
About LinkBacks



CornedBee