错误:“;期望的类名”;

Error: "expected class name"

本文关键字:期望 错误      更新时间:2023-10-16

我已经在这里搜索了其他"预期类名"错误问题,但它们都是"…在'{'标记之前"或"…在';'之前"。

解决方案是包含正确的文件,但我的文件包含了包含继承类的.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从未定义过。原因可能是头文件中的头保护冲突。