If you want to use a template, the entire template definition must be visible in the TU that creates the template instance. That way, you can simply enter the full definitions in the header file.
This is only if you really want the bodies of the classes and the bodies of the members of the class to be separated, then you might be tempted to put these function definitions in a separate file. However, the above rule still applies, so you will need to include a separate file along with the header so that anyone can use the template.
This is a matter of taste. If the member bodies are short, you can also define them in a string. Also keep in mind that functions defined inside a class definition are implicitly declared inline
, while you will need to specify this explicitly if you are writing bodies separately.
Partially specialized templates are still templates, so the same rules apply.
A fully specialized template template is just an ordinary class, so you are considering as such:
// FooInt.hpp template <typename> class Foo; template <> class Foo<int> { // your class here };
One thing you might have in mind is "explicitly instantiating a template", a la template class Foo<int>;
. This is something else; leave a comment if you are interested in using this.
source share