Hello, everyone.
I'm having some trouble with template class declarations and definitions, especially when they are split across several files.
As a test example, I did this:
In file "test.h", I declared:
Code:
template<class T>
class test
{
T t;
public:
void set_t(T k);
};
In file "test.cpp", I defined:
Code:
#include "test.h"
template<class T>
void test<T>::set_t(T k)
{
t = k;
}
and my main procedure is a very simple:
Code:
int _tmain(int argc, _TCHAR* argv[])
{
test<int> p;
p.set_t(10);
return 0;
}
(as you can see, I'm using VC++ 2003)
The problem is, my compiler keeps giving me a hard time about:
template_test error LNK2019: unresolved external symbol "public: void __thiscall test<int>::set_t(int)" (?set_t@?$test@H@@QAEXH@Z) referenced in function _main
It works fine if I just keep the function definition and declaration together, but obviously, I want to know how to split the two.
Thanks in advance, people.