Reputation: 36012
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?
Upvotes: 5
Views: 128
Reputation: 92391
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).
Upvotes: 2
Reputation: 96311
It's implied when it's in function parameter scope (but not in the return type). See also using nested classes as a parameter type.
Upvotes: 0