开发者

C++: Compile Error for Template Assignment Operator Overloading

I keep getting the error "use of class template requires template argument list" when I compile the following code in VC++6. What is wrong with it?

template <class T>  
class StdVector{  
    public:                 
        StdVector & operator=(const StdVector &v);
};

template <typename T>  
StdV开发者_StackOverflowector & StdVector<T>::operator=(const StdVector &v){  
    return *this;
}


You need to put the template parameter in the return type:

template <typename T>  
StdVector<T> & StdVector<T>::operator=(const StdVector &v)
{  
    return *this;
}


It should be

template <typename T>  
StdVector<T> & StdVector<T>::operator=(const StdVector<T> &v)
{  
    return *this;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜