tags:

views:

150

answers:

2

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>  
StdVector & StdVector<T>::operator=(const StdVector &v){  
    return *this;
}
+3  A: 

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

template <typename T>  
StdVector<T> & StdVector<T>::operator=(const StdVector &v)
{  
    return *this;
}
Charles Bailey
In the parameter too, yes?
GMan
Thanks! :) It works fine now.
Lopper
No, because by the time the compiler has reached the parameter list, it's effectively in the scope of the class and the template name is now equivalent to the full template id. But checking now you've sown the seeds of doubt!
Charles Bailey
Ha, I've always wrote them, here's the chance to learn my new thing for the day. :P
GMan
@GMan: No, `<T>` in the parameter declaration is optional.
AndreyT
Hm, good to know. Would you guys include it explicitly or not? Which do you find more readable?
GMan
Personally, I go without. It's not like there's usually a shortage of verbose template parameters in most C++ code.
Charles Bailey
+1  A: 

It should be

template <typename T>  
StdVector<T> & StdVector<T>::operator=(const StdVector<T> &v)
{  
    return *this;
}
fushar
There's no need to add `<T>` to the parameter declaration
AndreyT