【问题标题】:expected class-name before '{' token error'{' 标记错误之前的预期类名
【发布时间】:2017-02-19 13:31:11
【问题描述】:

我在我的 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

【问题讨论】:

    标签: c++ class templates inheritance header


    【解决方案1】:

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

    class wordSearch: public avlTree<something>
    

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

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

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多