Templates and nested classes/structures

后端 未结 2 1607
轮回少年
轮回少年 2021-01-11 22:04

I have a simple container :

template  list {
    public:
        struct node {
            nodeType info;
            node* next;
              


        
相关标签:
2条回答
  • 2021-01-11 23:01

    You need to tell the compiler that node is a type using the keyword typename.Otherwise it will think node as a static variable in class list. Add typename whenever you use node as a type in your implementation of list.

    0 讨论(0)
  • 2021-01-11 23:04

    that's because node is a dependent type. You need to write the signature as follows (note that I have broken it into 2 lines for clarity)

    template <class nodeType> 
    typename list<nodeType>::node* list<nodeType>::_search() 
    {
        //function
    }
    

    Note the use of the typename keyword.

    0 讨论(0)
提交回复
热议问题