相关疑难解决方法(0)

C++模板typename迭代器

请考虑以下头文件:

template <typename T> struct tNode
{
    T Data;                      //the data contained within this node
    list<tNode<T>*> SubNodes;       //a list of tNodes pointers under this tNode

    tNode(const T& theData)
    //PRE:  theData is initialized
    //POST: this->data == theData and this->SubNodes have an initial capacity
    //      equal to INIT_CAPACITY, it is set to the head of SubNodes
    {
        this->Data = theData;
        SubNodes(INIT_CAPACITY);   //INIT_CAPACITY is 10
    }

};
Run Code Online (Sandbox Code Playgroud)

现在考虑来自另一个文件的一行代码:

list<tNode<T>*>::iterator it();  //iterate through the SubNodes
Run Code Online (Sandbox Code Playgroud)

编译器给我这个错误消息: Tree.h:38:17: error: need ‘typename’ before ‘std::list<tNode<T>*>::iterator’ because ‘std::list<tNode<T>*>’ …

c++ templates iterator typename

39
推荐指数
3
解决办法
6万
查看次数

标签 统计

c++ ×1

iterator ×1

templates ×1

typename ×1