Let's say I have this to create a multidimensional array dynamically:
int* *grid = new int*[gridSizeX];
for (int i=0; i<gridSizeX; i++) {
grid[i] = new int[gridSizeY];
}
Shouldn't be possible now to access elements like grid[x][y] = 20?
Yes, this should work fine.
But... you might want to consider using standard containers instead of manually managing memory:
typedef std::vector<int> IntVec;
typedef std::vector<IntVec> IntGrid;
IntGrid grid(gridSizeX, IntVec(gridSizeY));
grid[0][0] = 20;
是的-但是在C / C ++中,它将以grid [y] [x]布局。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.