object return type for a class template function

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.

The return type should be const SimpleVector&

1
2
template<class T>
 const SimpleVector& SimpleVector<T>::operator=(SimpleVector &obj)
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.
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
Topic archived. No new replies allowed.