Ogh*_*ris 1 c++ inheritance class
我在这里搜索了其他"预期的类名"错误问题,但它们都是"......之前'{'标记'或"......之前';'".
解决方案是包含正确的文件,但我的文件包含包含继承类的.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;
};
Run Code Online (Sandbox Code Playgroud)
继承的类在bst.h中定义,因此我没有其他文件包含在项目中.
很抱歉这个简单的问题,我只是不知道为什么会发生错误.
更改
class SOBTree: public BinarySearchTree
Run Code Online (Sandbox Code Playgroud)
至
class SOBTree: public BinarySearchTree<T>
Run Code Online (Sandbox Code Playgroud)
..as BinarySearchTree,(肯定)也是一个模板.