object return type for a class template function

Mar 16, 2013 at 2:40am
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 2:49am
The return type should be const SimpleVector&

1
2
template<class T>
 const SimpleVector& SimpleVector<T>::operator=(SimpleVector &obj)
Mar 16, 2013 at 3:09am
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
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
Topic archived. No new replies allowed.