new keyword

how do I allocate multidimensional arrays using new?
I think you can use a for loop like this:

1
2
3
int **ptr = new int*[20];
for (int i = 0; i< 20; ++i)
     ptr[i] = new int[10];


But I thought there was a better way...
Now, excuse me if I'm wrong, but I would think you could do this:

1
2
3
int** ary = new int*[sizeX];
for(int i = 0; i < sizeX; ++i)
    ary[i] = new int[sizeY];


Remember to use delete. The int **art 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 delete[]
Topic archived. No new replies allowed.