Storing pointers in multi-dimensional array
- by sdfqwerqaz1
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?