C ++:编译错误:'<'标记之前的预期初始化程序

时间:2014-12-01 04:22:54

标签: c++ templates compiler-errors g++

这是一个与家庭作业相关的问题,但是编译问题不是作业,我已经实现了我需要编写的功能,现在只需要弄清楚这个编译错误。
我已经尝试过搜索,到目前为止,我得到的结果与我的问题接近,不适合导致编译错误的原因。

来自 binaryTree.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:错误:'&lt;'令牌之前的预期初始化程序

binaryTree.h:257:错误:'&lt;'令牌之前的预期初始化程序

createList()和inorderToList()的函数定义分别是第250行和第257行。所以我对这里的错误感到有些困惑,确定这很简单。

1 个答案:

答案 0 :(得分:0)

好的,弄清楚我做错了什么。

我最初在派生类(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]
}