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;
}
精彩评论