It looks to me that this is a confusing way of separating code. .h
stands for header and .hpp
for C++ header commonly. Putting template definitions into .hpp
while other code into .h
seems to abuse the file extension.
Template code is usually all written in one header together with the template declaration, or in another header that may also be specially suffixed like .tcc
or something and then included into the header where the template declarations are put in. But really, the file extension doesn't matter as long as you are consistent in your project.
Exceptions are when you use explicit instantiation, and know exactly what instantiations you will need. Imagine you have a template, and exactly two instantiations of it:
template<typename T>
struct SymbolTable {
T *lookup();
// ...
};
template struct SymbolTable<GlobalSym>;
template struct SymbolTable<LocalSym>;
You don't need to put the definition of lookup
and others into the header. You can put them all into a .cpp
file, alongside with the two explicit instantiation directives.
The last point you ask about is about a different topic: Explicit specializations. I recommend you to make a separate question about that. In a nutshell, explicit specialization definitions where all template arguments have concrete values/types should be put into the .cpp
file, but declarations of them are needed to be put into the header (to tell others that those certain members are specialized).