Click to See Complete Forum and Search --> : template problem


DarkLizener
January 5th, 2006, 10:42 AM
Hi
Here is my problem:class A
{
public:
// Constructor and so on....
template <typename T>
int func(T* const& var);
//....

// in the .cpp:
template <typename T>
int A::func(T* const& var) { var->DoSmth(); return 1; }I included the header into an other classes cpp like://class B .cpp
void B::somefunc()
{
A a;
CDoSmthClass *ds = new CDoSmthClass();
// now I want to call class A's func
a.func(ds);
// The linker fails at this point saying "... unresolved external... public: int __thiscall A::func.......When I use the func method eg. in class A's constuctor with the CDoSmthClass it compiles without link error!!???!?

RoboTact
January 5th, 2006, 11:18 AM
include implementation of a::func in header

exterminator
January 6th, 2006, 12:25 AM
There are many, many threads on this issue here .. try searching them here in this forum. You will find what needs to be done. In the meantime look at this FAQ - Why do I get unresolved externals with my template code? (http://www.codeguru.com/forum/showthread.php?t=250284). Hope this helps. Regards.