The compiler should see template definitions then it compiles code. So place all your template definitions of World in one header file and use it where template World is used.
Templates must be defined in the same translation unit where they are being used. Put the definition of the World constructors in World.hpp and it should work better.
1. You can't solve this with the word extern.
2. You can solve this by putting "class template World<2, 2>;"
3. You should realize how restricting this is to be placed in the implementation itself and not inlined.
Also, extern cannot solve the problem because type data isn't portrayed in binary (aside from debugging info but that's different entirely).
Instead, you should place the implementation of the template class in a header which ascertains it to being inlined (in 99% of cases anyways).
Another solution is using in-line files. In-line files contain the definition of templates. The file is then #included at the bottom of the header where the declaration is. The extension can be anything other than the extensions for header/source modules. For example:
Header:
1 2 3 4 5 6 7 8
#ifndef __HEADER_DEF__
#define __HEADER_DEF__
template< typename Type >
void Function( const Type &In_Data );
#include "In-line File.inl"
#endif
In-line File:
1 2 3 4 5
template< typename Type >
void Function( const Type &In_Data )
{
//...
}
...which is equivalent to:
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef __HEADER_DEF__
#define __HEADER_DEF__
template< typename Type >
void Function( const Type &In_Data );
template< typename Type >
void Function( const Type &In_Data )
{
//...
}
#endif
You're still required to include everything inside of the "inl" file which increases compile-times, you're required to repeat literally every single template definition a second time, it adds yet another file into the codebase, and reduces code-readability since you must open yet another file to figure out the definition of the template functions.
Yeah, sorry, won't be using that one anytime soon.
1) Inline your template function.
2) Explicitly declare your template function/class with template parameters to make an instance of that template in implementation. Generally called "explicit template instantiation".
The first one is simple and flexible. The second one is confusing, inflexible, and really bad practice (in most cases). In your case, you *want* to inline your template because there's generally never going to be a case where you know what template parameters you pass to the template function.