A slight short answer: you used _T in the user code, so your entire program is poorly formed and does not require diagnostics; identifiers consisting of _ followed by a capital letter are reserved for use in the implementation.
In this sense, both examples are exactly equivalent.
Ignoring this error, they are not identical.
The first is an operator that is not a member of template += .
The second element is a non-template += template class that takes an implicit this as its first parameter.
These are very different things. template conformance to the function template does not make any transformations (except for basic ones); template methods can convert.
In the second case, the non-template operator+= is able to convert its second argument to the _T type. In the first case, the operator+= pattern will not try to convert while the pattern matching types.
Actually there is a 3rd feature, which I often prefer:
template < class T > struct A { operator T () const { return 42 ; } friend A& operator += ( A& l, T r ) { return l; (void)r; } };
where we do free += as a friend. This creates a non-pattern += that takes two arguments and is therefore more symmetrical.
Such friends without templates can be found through ADL.
living example .
Aside, they also differ because a pointer to one can be stored in A<_T>& (A<_T>::*)( _T ) , the other as A<_T>& (*)(A<_T>&, _T) . They are not identical and cannot be converted between them.
Yakk
source share