C++:编译错误:"<"标记之前的预期初始值设定项
C++: Compile Error: expected initializer before ‘<’ token
这是一个与家庭作业相关的问题,但编译器问题不是家庭作业,我已经实现了我需要编写的函数,现在只需要弄清楚这个编译器错误。
我尝试过搜索,到目前为止,我得到的结果与我的问题接近,不符合导致编译器错误的原因。
从二进制树.h :
#include <iostream>
#include "orderedLinkedList.h"
using namespace std;
// Definition of the Class
template <class elemType>
class binaryTreeType
{
[rest of definition]
public:
[rest of declarations]
void createList(orderedLinkedList<elemType>& list);
[rest of declarations]
private:
void inorderToList(nodeType<elemType> *p, orderedLinkedList<elemType>& tList) const;
[.... then the definitions]
template <class elemType>
void bSearchTreeType<elemType>::createList(orderedLinkedList<elemType>& tList)
{
inorderToList(this->root, tList);
}
// copies to list
template <class elemType>
void bSearchTreeType<elemType>::inorderToList(nodeType<elemType> *p,
orderedLinkedList<elemType>& tList) const
{
if (p != NULL)
{
inorder(p->lLink);
tList.insert(p->info);
inorder(p->rLink);
}
}
我收到错误:
binaryTree.h:250:错误:"<"标记之前的预期初始值设定项
binaryTree.h:257:错误:"<"标记之前的预期初始值设定项
createList() 和 inorderToList() 的函数定义分别是第 250 行和第 257 行。 所以我有点困惑我在这里做错了什么,当然这很简单。
好的,弄清楚我做错了什么。
我最初将模板放在派生类 (bSearchTreeType) 中,当我将其移动到父类中时忘记更新方法定义。
所以新代码(第 250 和 257 行):
template <class elemType>
// below is 250
void binaryTreeType<elemType>::createList(orderedLinkedList<elemType>& tList)
{
[... same as in original post]
}
template <class elemType>
// below is 257
void binaryTreeType<elemType>::inorderToList(nodeType<elemType> *p,
orderedLinkedList<elemType>& tList) const
{
[... same as in original post]
}
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译