Original Post
Hello,
I am having a problem with a template class I created. The problem I am having concerns how to use it. here is how I have my files set up...
---------------
chash.h
I define the template class here...
---------------
chash.cpp
The implementation of the template class is here...
---------------
now I want to use this class elsewhere in other files, this is where I am having problems. I have a manager type class that contains an instance of the template hash class, like this
---------------
manager.h
#include "chash.h"
chash *framehash;
---------------
manager.cpp
//in the constructor
framehash = new chash;
---------------
Now here comes the problem, everything compiles ok but I get linker errors saying basically that manager.obj cant find the chash functions to link to.
I can solve this by explicitly instantiating a chash inside chash.cpp... which becomes
---------------
chash.cpp
template class chash;
//the rest..
---------------
I cant put the explicit instantiation anywhere else or I get compile errors. This just does not seem right to me. chash.cpp should not be ''aware'' of all the classes that will use it - that seems to defeat the purpose.
All the examples of using template classes in every book I have put all the code into one file. I am just unsure how to do it and span it to many files.
Hope you can understand my problem,
Maybe if anyone has any example of using a template class in a practical - multifile - project.
thanks,
BrianH