# Multidimensional containers

## Recommended Posts

Drakkcon    612
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 on other sites
Telastyn    3777
I am not familiar with STL so I can't say for sure, but you should be able to make a vector <vector< whatever >>

##### Share on other sites
This is how you do what you are trying to do:

vector< vector< whatever > > names;

##### Share on other sites
Zahlman    1682

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 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 on other sites
Drakkcon    612
Quote:
 id recommend using a typedef =)

You just saved me a ton of typing!

Quote:
 vector< vector< whatever > > names;

Thanks!

I never knew how to do this, rate-ups for all!

##### Share on other sites
petewood    819
It's possibly better to use the boost.multi_array library.