I'm working on exploring some new pathfinding code and currently have a problem.
I have a stl list of Tiles. I have written a search function that should search the stl list and return a pointer to the memory location of the Tile.
However, it appears that what I'm doing will not work because it wants to use a pointer to an iterator rather than a pointer to a Tile.
The understandable error:
/home/ryan/Dropbox/Rpath/main.cpp|110|error: cannot convert ‘std::_List_iterator<Tile>*’ to ‘Tile*’ in return|
struct Tile
{
public:
int x,y,value,g,h,f; // a non zero value means unwalkable
Tile * parent;
Tile(Tile * parent, int x, int y, int g, int h, int value)
{
this -> parent = parent;
this -> x = x;
this -> g = g;
this -> h = h;
this -> value = value;
this -> f = g + h;
}
bool operator == (Tile& compare)
{
// Tiles are only compared on x and y values
// other variables are not taken into account
if(compare.x != x) return false;
if(compare.y != y) return false;
return true;
}
bool operator < (const Tile& compare)
{
if(f < compare.f) return true;
}
};
// now the function that cannot compare an stl list iterator pointer to a Tile.
Tile* find_by_value(list<Tile>& my_list, Tile &my_tile)
{
// return true if a similar tile is found
for(list<Tile>::iterator i = my_list.begin(); i != my_list.end(); i++)
{
if(*i == my_tile) return &i;
}
return NULL;
}
The function is supposed to take a Tile and search the stl list to find a matching one, returning a pointer to the matching Tile.[/code]