Neither C nor C++
really support multidimensional arrays. You can either allocate a 'normal' 1D array and index it manually, or create an array of arrays. Furthermore, a pointer is
always seen as a unidimensional array, so with int *p; you can
never write p[a]
.
All things considered, you really just should use a std::vector<int> and write vec[x+y*row_size] instead of vec[y][x].
Or use
boost::multi_array.
Edit: Jingo, your code is an utter abomination.
p[0] = new int[amount];p[1] = new int[amount];p[2] = new int[amount];
would be correct, but even then, would result on a 3xN array of arrays, not a Nx3 bidimensional array.
And of course, if you ever call allocate() twice... you'll still leak memory.
[Edited by - Fruny on January 1, 2005 1:17:15 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan