C++禁止声明...在将结构传递给函数时没有类型错误

mad*_*max 1 c++ struct list

我无法弄清楚我在这里做错了什么.
我想对列表进行排序并使用比较函数对其进行排序.
找到一个代码示例,确切地解决了我的问题,但它对我不起作用.

我总是得到这个错误:
错误:ISO C++禁止声明'Cell'没有类型

Cell不是我的类型吗?

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_;
        }
  };

};
Run Code Online (Sandbox Code Playgroud)

AStarPlanner.cpp

 bool AStarPlanner::compare(const Cell& first, const Cell& second)
 {
    if (first.f_ < second.f_)
       return true;
    else
       return false;
 }
Run Code Online (Sandbox Code Playgroud)

Luc*_*ore 7

移动Cell方法声明之前的声明.

class AStarPlanner {
public:
  AStarPlanner();
  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
        Cell(int x, int y, int g, int h) : x_(x), y_(y), g_(g), h_(h) {
                f_ = g_ + h_;
        }
  };
  bool compare(const Cell& first, const Cell& second);
};
Run Code Online (Sandbox Code Playgroud)

另外,从技术上讲,没有Cell类型,但AStarPlanner::Cell(但它会在上下文中自动解决class).