2D Dynamic Array

solved
Last edited on
If you are using the vector class then you can just make a vector of vectors (array of arrays, all the same).
 
vector<vector<char>> gamemap


in order to build it just use

1
2
3
4
for ( i=0; i < (# of rows or row.size(), whatever size it will be); i++){
 gamemap.push_back(vector<char> row)
}
return gamemap


something along those lines would build it. I don't know your specifics but this is a pretty straightforward way you can do it and if you know how to build your row vectors already then this shouldn't add to much to do what you want.

Then in order to access any give place in your gamemap it's just gamemap[i][j] and you can work with gamemap as you would any matrix really.
Last edited on
Right now I have this:

a private variable in my class of: char** gamemap;

I have an initializer of:

1
2
3
4
5
6
7
8
// Load Saved File

	mapRows = 15;
	mapColumns = 51;

	gamemap = new char*[mapRows];
	for (int k = 0; k < mapRows; k++)
    gamemap[k] = new char[mapColumns];


It works successfully, but then I dont know how to add my map like I have above into it.
Last edited on
bump.
Topic archived. No new replies allowed.