[C++] pointer to a 2D array of objects?

Soldato
Joined
23 May 2005
Posts
2,964
Location
Auckland, New Zealand
instead of this:

Tile * Grid = new Tile[GRIDWIDTH*GRIDHEIGHT];

I'd like a 2D array but this doesn't work:

Tile * Grid = new Tile[GRIDWIDTH][GRIDHEIGHT];

Anyone care to help? I know theres probably an easy solution to this.

Joe :)
 
or use STL vectors:

typedef std::vector<Tile> TileVec;
typedef std::vector<TileVec> GridType;

...

GridType Grid (GRIDWIDTH, TileVec (GRIDHEIGHT));

...initialise tiles...

std::cout << Grid[0][0];

How would I delete an array when declared like this? I know that its deleted when a program is closed but how would I delete it manually?
 
Back
Top Bottom