template<typename T> ClassA
{
...
ClassA& operator=(const ClassA&);
...
};
// case one:
template<typename T>
ClassA<T>& ClassA<T>::operator=(const ClassA &rhs)
{ ... }
// case two:
template<typename T>
ClassA<T>& ClassA<T>::operator=(const ClassA<T> &rhs)
{ ... }
I assume case one is correct.
Question> Why we don't have to use ClassA<T>
in the function parameter list such as in case two?
As you have seen, either version will work.
Once we have passed the ClassA<T>::
part of ClassA<T>& ClassA<T>::operator=(const ClassA& rhs)
it behaves as if we were inside the class. For example, the operator can access all the members of the class.
You do have to specify the full name for the return value, because at that point we still don't know that this is a member function (or operator).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With