Templates are not types. These are just templates. They become only a type when they are created (with a full set of parameters).
Compilation requires that all necessary type definitions be available at compile time. Moreover, binding requires that all necessary function definitions, including member functions, exist in some translation unit (with an attachment providing the usual exception for a rule with one definition).
If you put all this together, it almost automatically follows that the entire definition of the function of the template member of the template class should be available for each instance of the template used at some point in the compilation process.
On the other hand, consider the following setting:
// Header file: template <typename T> struct Foo { void f(); } // "Implementation" file template <typename T> void Foo::f() { /* stuff */ }
If you compile an implementation file, it does not contain any code, since the template instance is not compiled. The user of the header file can create an instance of Foo<int> , but the class body is never created in any TU, so you get a linker error when building the program.
This can help think of patterns as a tool for generating code, rather than actual code, at least for compilation.
source share