Possible Duplicate:
Why should the implementation and the declaration of a template class be in the same header file?
Do template class member function implementations always have to go in the header file in C++?
Ive made some stupid mistake here but i cant see what.
this compiles:
//start of header.h
namespace ns
{
class A
{
public:
template <class t>t func();
};
template<class t> t A::func()
{
t a;
return a;
}
}
//end of header.h
//start of imp.cpp
//end of imp.cpp
but the following does not:
//start of header.h
namespace ns
{
class A
{
public:
template <class t>t func();
};
}
//end of header.h
//start of imp.cpp
#include "header.h"
using namespace ns;
template<class t> t A::func()
{
t a;
return a;
}
//end of imp.cpp
the error is : error LNK2019: unresolved external symbol "public: int __thiscall ns::A::func(void)" (??$func@H@A@ns@@QAEHXZ) referenced in function _main