I used to put my methods implementation together with class definition in the header file. I would like to separate them. The following are my new code:
I got the following linking error,Code:// File: MyClass.h #ifndef __MYCLASS_HEADER__ #define __MYCLASS_HEADER__ template <class t> class MyClass { public: void doNothing(t var); }; #endif // __MYCLASS_HEADER__ // File: MyClass.cpp #include "MyClass.h" template <class t> void MyClass<t>::doNothing(t var) { var = var; } // File: MyMain.cpp #include "MyClass.h" int main() { MyClass<int> myClass; return 0; }
error LNK2001: unresolved external symbol "public: void __thiscall MyClass<int>::doNothing(int)" (?doNothing@?$MyClass@H@@QAEXH@Z)
I must have missed something. Anyone can help?