Storing pointers in multi-dimensional array

Posted by sdfqwerqaz1 on Stack Overflow See other posts from Stack Overflow or by sdfqwerqaz1
Published on 2011-02-05T23:15:27Z Indexed on 2011/02/05 23:25 UTC
Read the original article Hit count: 187

Filed under:
|

My intention is to create a dynamic 3D array in C++ using pointers.

MyType*** myArray;
myArray = new MyType**[GRID_SIZE];
for (int i = 0; i < GRID_SIZE; ++i) {
  myArray[i] = new MyType*[GRID_SIZE];
  for (int j = 0; j < GRID_SIZE; ++j) {
    myArray[i][j] = new MyType[GRID_SIZE];
  }
}

Now this 3D array is ready to store MyType instances. What is the correct syntax needed when declaring this array if I want to store pointers to MyType instead of just MyType objects in this array?

© Stack Overflow or respective owner

Related posts about c++

Related posts about multidimensional-array