c++ - "{" token 错误之前的预期类名

标签 c++ class templates inheritance

好吧,我已经检查了缺少的分号,据我所知我没有任何包含循环,所以我有点难过。我一直在查看发布的其他示例,但我仍然不太明白我遗漏了什么。我猜这与我没有正确处理的模板的使用有关,但我真的不知道。

In file included from customtester.cpp:6:0:
MyBSTree.h:23:1: error: expected class-name before â{â token

文件:

#ifndef MYBSTREE_H
#define MYBSTREE_H

template <typename T>        //not sure which of these I need,
class AbstractBSTree;        //the include, the forward
#include "abstractbstree.h"  //declaration, or both.

template <typename T>
class TreeNode
{
    T m_data;
    TreeNode<T> * m_right;
    TreeNode<T> * m_left;

};

template <typename T>
class MyBSTree:public AbstractBSTree //this would be line 23
{
    TreeNode<T> * m_root;
    int m_size;
};

#endif

有什么我想念的吗?我不能修改“abstractbstree.h”

最佳答案

尝试:

public AbstractBSTree<T>

编译器将假定 <T>仅在模板体内且仅用于模板化类,不在公共(public)空间

关于c++ - "{" token 错误之前的预期类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19994729/

相关文章:

c++ - 在 C++ 中使用函数模板作为模板模板参数

c++ - 有没有更好的方法将流上的函数链接在一起?

c++ - 默认初始化和值初始化结构的不同性能

c++ - fork() 和 waitpid() 不等待 child

c++ - 从 C++ 模板返回 NULL

php 类...验证

c++ - 调整 vector vector 的大小会导致段错误

function - Dart类中的静态调用方法(使类可调用)

c++ - 通用类型别名,它们彼此不兼容

具有多个输出端口的 C++ 管道段 - 类型匹配