Hi everyone,
I have a function "load_tiles" that creates and returns a pointer to an array of pointers.
To fill up the array, I use a for loop. Initially it was something like for(int i = 0; i < TOTAL_TILES, i++); however now I want to transform it to use pointers to increment - mostly for the experience, but the performance bit too ![]()
The problem is that when I want to access an element in the array to set whether it's walkable or not, I get an "expression must have a pointer to class type" error.
c_Tile** tileArray = new c_Tile*[TOTAL_TILES];
for (c_Tile **ptr = tileArray; ptr < (tileArray + TOTAL_TILES); ptr++)
{
short tileType = -1;
map >> tileType;
if ( tileType >= 0 && tileType <= 12 )
{
*ptr = new c_Tile(x, y, tileType);
if ( tileType >= 3 && tileType <= 12 )
{
**ptr->setWalkable(false); /*I know there's something wrong with this, but what?*/
c_Entity_is_movable::unWalkables.push_back(*ptr);
}
else
**ptr->setWalkable(true); /*I know there's something wrong with this, but what?*/
}
else
SDL_Quit();
x += TILE_WIDTH;
if ( x >= LEVEL_WIDTH )
{
x = 0;
y += TILE_HEIGHT;
}
}
I've tried also tried *ptr->setWalkable(true), but to no avail - I already know why it doesn't work but it seemed worth a try. To me, **ptr->foo() makes sense since it's a pointer to a pointer; so I dereference twice and should be at a c_Tile*.






