When you define your template in a .cpp file, you need to explicitly create an instance of it with all the type / template parameters known as the template will be used in advance (put it in the .cpp file):
template class TreeNode<Player>;
If you do not know with what template parameters the template will be used, you should put all the definitions in the header. as
template<typename T> class TreeNode { public: TreeNode() { doSomething(); } };
The reason is that when you are going to use the template somewhere, the compiler should be able to generate code for this particular copy of the template. But if you put the code in a .cpp file and compile it, the compiler will not be able to process the code to create the instance (unless you use the notorious export keyword, which only supports a few compilers).
This is also a post in my answer to C ++ Pitfalls: What C ++ pitfalls should be avoided?
Johannes Schaub - litb
source share