繁体   English   中英

使用类模板需要模板参数列表,该怎么办?

[英]use of class template requires template argument list, what do?

我正在创建此模板类

template <class T> class ArrayLLN {
     private:
     ArrayLLN *next;
     T *item;
public:
     ArrayLLN(T i, ArrayLLN *n);
     ~ArrayLLN();
     void insert(T n, int i, int m);
     ArrayLLN *getnext();
     T *getitem();
     T remove(int i, int m);
};

我遇到问题的方法如下。

ArrayLLN *getnext();

并写为

template <class T> ArrayLLN ArrayLLN <T> :: *getnext(){return next;}

目前,我收到错误消息“错误C2955:'ArrayLLN':使用类模板需要模板参数列表”

以下配置产生了其他错误

template <class T> ArrayLLN *ArrayLLN <T> :: getnext(){return next;)

如何解决此错误?

可能是这些声明吗?

template <class T> T *ArrayLLN<T>  :: getitem(){return item;}
template <class T> ArrayLLN<T> *ArrayLLN<T>::getnext() { return next; }
template <class T> T ArrayLLN <T> :: remove (int i, int m){
    T *tmp == NULL;
    if(i == m && next){
        tmp = item;
        item = next ->getitem();
        next = next->getnext();
    }
    else if (i > m){
        m++;
        tmp = next -> remove(i,m);
    }
    return tmp; 
 }

正确的语法如下:

                        //  +-- argument list here                    +-- bracket
                        //  v                                         v not paren
template <class T> ArrayLLN<T> *ArrayLLN<T>::getnext() { return next; }

在类内部,ArrayLLN是注入的类名称 ,允许您省略模板参数列表。 在课程之外,您必须提供它。 其次,星星位置错误。

template <class T> ArrayLLN<T>* ArrayLLN <T> :: getnext(){return next;}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM