Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;禁止申报。。。向函数传递结构时没有类型错误_C++_List_Struct - Fatal编程技术网

C++ C++;禁止申报。。。向函数传递结构时没有类型错误

C++ C++;禁止申报。。。向函数传递结构时没有类型错误,c++,list,struct,C++,List,Struct,我不知道我在这里做错了什么。 我想对列表进行排序,并使用比较函数对其进行排序。 找到了一个代码示例,在该示例中,我的问题得到了解决,但它对我不起作用 我总是遇到这样的错误: 错误:ISO C++禁止声明“Cype”,没有类型< /强> 手机不是我喜欢的类型吗 阿斯塔普兰纳 class AStarPlanner { public: AStarPlanner(); virtual ~AStarPlanner(); protected: bool compare(const C

我不知道我在这里做错了什么。
我想对列表进行排序,并使用比较函数对其进行排序。
找到了一个代码示例,在该示例中,我的问题得到了解决,但它对我不起作用

我总是遇到这样的错误:
<强>错误:ISO C++禁止声明“Cype”,没有类型< /强>

手机不是我喜欢的类型吗

阿斯塔普兰纳

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

};
阿斯塔普兰纳

 bool AStarPlanner::compare(const Cell& first, const Cell& second)
 {
    if (first.f_ < second.f_)
       return true;
    else
       return false;
 }
bool AStarPlanner::比较(常量单元格&第一个,常量单元格&第二个)
{
if(first.f_uu
单元格的声明移动到方法声明之前

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

另外,从技术上讲,没有
单元格
类型,而是
AStarPlanner::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);
};

另外,从技术上讲,没有
单元格
类型,只有
AStarPlanner::Cell
(但它是在
的上下文中自动解析的)。

C++关于类声明中名称可见性的规则并不明显。例如,您可以有一个引用成员的方法实现,即使该成员稍后在类中声明。。。但是,如果稍后声明嵌套类型,则不能有引用该类型的方法声明

在类的开头移动嵌套类型声明可以解决本例中的问题


没有限制这个技术的原因(或者说我不知道它是什么,但是我从来不敢写完全的C++解析器)。然而,这就是语言的定义方式。

C++关于类声明中名称可见性的规则并不明显。例如,您可以有一个引用成员的方法实现,即使该成员稍后在类中声明。。。但是,如果稍后声明嵌套类型,则不能有引用该类型的方法声明

在类的开头移动嵌套类型声明可以解决本例中的问题

没有限制这个技术的原因(或者说我不知道它是什么,但是我从来不敢写完全的C++解析器)。然而,这就是语言的定义方式