Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
x
gridSizeX
y
gridSizeY
std::vector
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;
Add a comment
Yes - but in C/C++ it will be laid out as grid[y][x].
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
xis within [0,gridSizeX) andyis within [0,gridSizeY).} I recommend you usestd::vectorto manage memory for you.