错误:“;期望的类名”;
Error: "expected class name"
我已经在这里搜索了其他"预期类名"错误问题,但它们都是"…在'{'标记之前"或"…在';'之前"。
解决方案是包含正确的文件,但我的文件包含了包含继承类的.h文件。
#include "BinaryNode.h"
#include "bst.h"
template <class T>
class SOBTree: public BinarySearchTree { //Expected Class Name
public:
void insert( const T& x );
void remove( const T& x );
int reportComparisonCount();
double reportCPUTime();
private:
void insert( const T & x, BinaryNode<T> * & t );
void RotateRight(BinaryNode<T> * & root );
void RotateLeft(BinaryNode<T> * & root );
BinaryNode<T> *root;
};
继承的类是在bst.h中定义的,所以我没有其他文件可以包含在项目中。
很抱歉问了这么简单的问题,我只是不知道为什么会发生错误。
更改
class SOBTree: public BinarySearchTree
至
class SOBTree: public BinarySearchTree<T>
BinarySearchTree也是一个模板。
BinarySearchTree是否可能也是一个模板,并且需要从BinarySearchTree<T>
派生?
否则,很明显BinarySearchTree从未定义过。原因可能是头文件中的头保护冲突。
相关文章:
- 提升精神 x3 错误处理程序与期望
- 我一直得到一个期望;错误,我不确定为什么
- 使用 gtest EXPECT_CALL 时竞争条件段错误,而另一个期望是执行相同的方法
- Variadic模板:候选人期望1个参数,0提供(扣除错误)
- 我有 3 个错误:期望一个")",期望一个表达式,long 类型的参数与 U32 类型的参数不兼容
- 错误:“;期望的类名”;
- 错误C2057:期望的常量表达式
- 错误:')'令牌强制转换问题之前期望的主表达式
- Boost Python运行时错误,将派生类型的对象从Python传递给c++函数,期望将shared_ptr传递给基类
- 语法错误,意外的标记,期望文件结束
- 错误:当通过P2P通道连接两个NodeContainers时,期望主表达式在ns3中的const之前
- 错误:':'令牌之前期望的初始化项
- c++ -错误:在'{'标记之前期望的类名
- 错误:期望声明
- 试图为继承类的子类编写构造函数,猜测语法,期望的主表达式错误
- if语句中的函数:期望的错误表达式
- 编译错误:solution.c:20:5: Error:期望的标识符或'('在' {' token{之前
- QT 5.2.1编译错误;在'delete'之前期望的非限定id
- 程序没有给出期望的输出.FIFO的错误实现
- 编译时错误:期望的构造函数、析构函数或转换