I’m writing a template class, let’s say
template <class T>
class bla {
bla() ;
~bla() ;
};
template <class T>
bla<t>::bla(){}
template <class T>
b<t>::~b(){}
This works fine as long as T is int, char, and so on … but in case that it will be a custom class MyClass, it will requiere the headerfile MyClass.h to be included, or am I wrong?
Question: How can this be done in a template-ish way, i.e. something like
#include "T.h"
Cheers!
When you use
bla<MyClass>you need to have included the definition ofblaand the definition ofMyClass. It isn’t necessary thatMyClassis known whenblais defined. The magic about this is called “two-phase name look-up”: while compiling the template definition all names not depending on the template parameter are looked up. During the second phase, when the template is instantiated, all remaining names are looked up in the context of the instantiation.