It is explicitly specified by the language standard in 14.6.1/1:
Within the scope of class template,
when the name of the template is
neither qualified nor followed by <,
it is equivalent to the name of the
template followed by the
template-parameters enclosed in <>.
This was re-worded (through the concept of "injected class name") in the later versions of the standard, but the point is that this behavior is explicitly spelled out in the document.
To answer the second part of your question, this rule also applies to parameter declarations when writing out-of-class method definitions, but it doesn't apply to the return type declarations. For example, this code is OK
template <typename T> struct S {
S foo(S);
};
template <typename T> S<T> S<T>::foo(S s) {
/* whatever */
}
but you can't remove the <T>
bit from the return type in the definition of the method. (And you can't remove <T>
from the qualified name of the method.)
As for the constructior specifically: your should use the full name (with <T>
) for the class, but you should not use <T>
in the name of the constructor itself. So the shortest form for out-of-class definition in your case would be
template <typename T> Wrapper<T>::Wrapper(const Wrapper& w) : t_(w.t_)
{
}
Note, that you can't add the <T>
bit to the constructor name even if you want to
template <typename T> Wrapper<T>::Wrapper<T>(const Wrapper& w)
^ ERROR !!!
P.S. This last claim needs further research. Comeau Online compiler thinks it is an error, while GCC thinks it is OK. I'll return to it later.
P.P.S. The compiler in MSVC++ 2005 complains about the latter declaration with a warning
warning C4812: obsolete declaration style: please use 'Wrapper<T>::Wrapper' instead
Interesting...