在'{'令牌错误

问题描述:

之前预期的类名称我在C++中出现'{'token'之前的预期类名“。我试图将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>