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