Sign in to follow this  
Drakkcon

Multidimensional containers

Recommended Posts

Is it possible to have multi-dimentional containors that are part of the STL. I was hoping I would be able to have an 'unlimited' isometric map with layers. so would vector <whatever> name[2][2] create a 3D array? Is there a way to do this?

Share this post


Link to post
Share on other sites
+1 to GreenToad.

Note that it is necessary to have a space between the closing angle brackets - otherwise the lexer sees a shift operator, and the rest of the compiler gets very confused.

Share this post


Link to post
Share on other sites
well, i think he wants to have many layers in his map an "infinite" (IE expandable) layered map.

for this you would need the extremely ugly but flexible vector of vectors of vectors.

vector< vector < vector<Tile> > > map;

then you could do

map[layer][x][y]

if you want to add a new layer, just do

map.push_back(vector< vector <Tile> >);

initialization would be something like


for(int l = 0; l < blah; l++)
{
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
map[l][x][y].stuff = blah;
}
}
}


id recommend using a typedef =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this