how do I allocate multidimensional arrays using new?
I think you can use a for loop like this:
int **ptr = new int*;
for (int i = 0; i< 20; ++i)
ptr[i] = new int;
But I thought there was a better way...
Now, excuse me if I'm wrong, but I would think you could do this:
int** ary = new int*[sizeX];
for(int i = 0; i < sizeX; ++i)
ary[i] = new int[sizeY];
Remember to use
is a pointer to a pointer. Or you could use c++ vectors.
Ignore my post I was editing while he posted it ;).
If you use
new then you've got to
Topic archived. No new replies allowed.