令牌错误之前'{'预期类名

expected class-name before '{' token error

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

在我的c++中,我得到了错误"在'{'令牌之前预期的类名"。我试图将avlTree类继承为单词搜索类,但它不工作。

#ifndef WORDSEAR_H
#define WORDSEAR_H
#include <string>
#include "avlTree.h"
class wordSearch: public avlTree  
{                                  <----error right here 
public:
//functions are here
private:
};
#endif

这是avlTree.h

#ifndef AVLTREE_H
#define AVLTREE_H
template <class myType>
struct nodeType {
myType  keyValue;
nodeType<myType>    *left;
nodeType<myType>    *right;
};
template <class myType>
class avlTree
{
public:
//functions are here
private:
};
#endif

avlTree是一个类模板,您需要为它指定模板参数:

class wordSearch: public avlTree<something>

根据您的意图,您也可以制作wordSearch类模板:

template <typename myType>
class wordSearch: public avlTree<myType>