M
Mark
hi, I need some help declaring a matrix of pointers. I made an image
to illustrate what I had in mind...
http://www.sfu.ca/~mnb2/matrix.gif
and here's the relevant code I'm working with (doesn't work)
class Tile
{
public:
SDL_Surface *img;
bool (*col)();
Tile(char* filename) {
img = IMG_Load(filename);
}
};
Tile square("img/square.png");
Tile triangle("img/triangle.png");
class Map
{
Tile ***tile;
Map()
{
tile = new *Tile[16][16];
I can't use tile = new Tile[16][16]; because then it actually tries to
construct each of the tiles, when I just want a matrix of pointers,
and I will assign each tile later individually.... like so
for(int y=0; y<16; y++)
{
for(int x=0; x<16; x++)
{
switch( rand()%2 )
{
case 0:
tile[x][y] = square;
break;
case 1:
tile[x][y] = triangle;
break;
}
}
}
}
I can't seem to figure out the proper syntax...
also..how would I properly delete this?
delete [][]tile?
to illustrate what I had in mind...
http://www.sfu.ca/~mnb2/matrix.gif
and here's the relevant code I'm working with (doesn't work)
class Tile
{
public:
SDL_Surface *img;
bool (*col)();
Tile(char* filename) {
img = IMG_Load(filename);
}
};
Tile square("img/square.png");
Tile triangle("img/triangle.png");
class Map
{
Tile ***tile;
Map()
{
tile = new *Tile[16][16];
I can't use tile = new Tile[16][16]; because then it actually tries to
construct each of the tiles, when I just want a matrix of pointers,
and I will assign each tile later individually.... like so
for(int y=0; y<16; y++)
{
for(int x=0; x<16; x++)
{
switch( rand()%2 )
{
case 0:
tile[x][y] = square;
break;
case 1:
tile[x][y] = triangle;
break;
}
}
}
}
I can't seem to figure out the proper syntax...
also..how would I properly delete this?
delete [][]tile?