I can’t figure out what I am doing wrong here.
I want to sort a list and have a compare function to sort it.
Found a code example where exactly my problem was solved but it doesn’t work for me.
I always get this error:
error: ISO C++ forbids declaration of ‘Cell’ with no type
Isn’t Cell my type?
AStarPlanner.h
class AStarPlanner {
public:
AStarPlanner();
virtual ~AStarPlanner();
protected:
bool compare(const Cell& first, const Cell& second);
struct Cell {
int x_;
int y_;
int f_; // f = g + h
int g_; // g = cost so far
int h_; // h = predicted extra cost
Cell(int x, int y, int g, int h) : x_(x), y_(y), g_(g), h_(h) {
f_ = g_ + h_;
}
};
};
AStarPlanner.cpp
bool AStarPlanner::compare(const Cell& first, const Cell& second)
{
if (first.f_ < second.f_)
return true;
else
return false;
}
Move the declaration of
Cellbefore the method declaration.Also, technically, there’s no
Celltype, butAStarPlanner::Cell(but it’s resolved automatically in the context of theclass).