C ++: compilation error for redirecting template operator

I keep getting the error "using a class template requires a list of template arguments" when compiling 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>  
StdVector & StdVector<T>::operator=(const StdVector &v){  
    return *this;
}
+3
source share
2 answers

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

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

It should be

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

Source: https://habr.com/ru/post/1724161/


All Articles