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++解析器)。然而,这就是语言的定义方式