I have a class with a struct in it and a list with these structs.
But when I iterate through this list I can’t get the properties out of my struct.
error: request for member ‘x_’ in ‘it.std::_List_const_iterator<_Tp>::operator* with _Tp = AStarPlanner::Cell*’, which is of non-class type ‘AStarPlanner::Cell* const’
Header file:
class AStarPlanner {
public:
AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap);
virtual ~AStarPlanner();
protected:
struct Cell {
int x_;
int y_;
int f_; // f = g + h
int g_; // g = cost so far
int h_; // h = predicted extra cost
//CellInfo* visited_from_; // pointer to cell from which this cell is visited
Cell(int x, int y, int g, int h) : x_(x), y_(y), g_(g), h_(h) {
f_ = g_ + h_;
}
};
bool cellInList(const Cell* cell, const std::list<Cell*> liste);
};
cpp file:
bool AStarPlanner::cellInList(const Cell* cell, const list<Cell*> liste)
{
list<Cell*>::const_iterator it;
for (it = liste.begin(); it != liste.end(); it++)
{
if ( it->x_ == cell->x_ && it->y_ == cell->y_)
return true;
}
return false;
}
You have a
list<Cell*>, so you need to dereference the iterator and the pointer.