2016-10-11 88 views
0

之前預期的類名稱我在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 

回答

4

avlTree是一個類模板,需要指定模板參數吧:

class wordSearch: public avlTree<something> 

根據你的意圖,你可能會做wordSearch班級模板太:

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