Mar 16, 2013 at 2:40am UTC
My book has the following header for a class template overloaded = operator:
template<class T>
SimpleVector<T>::operator=(SimpleVector &obj)
My issue is that they forgot the return type. Since the return is *this, should the header be:
template<class T>
SimpleVector * SimpleVector<T>::operator=(SimpleVector &obj)
Or do I need the <T> in the return data type? I would appreciate any help on this. Thanks.
Mar 16, 2013 at 3:09am UTC
Thanks for the reply but I'm not sure about the const. The vector is being created or replaced so I don't think that would work. I could be wrong. I'm still figuring out const and pointers.
Mar 16, 2013 at 3:18am UTC
You're right, there shouldn't be a const on there:
1 2
template <class T>
SimpleVector<T>& SimpleVector<T>::operator =(const SimpleVector<T>& obj)
Note that the argument should be const however.
Last edited on Mar 16, 2013 at 3:19am UTC