This is a simple class to illustrate the problem:
class ClassA
{
public:
template<typename T>
void Method1(T&& a) {};
};
Then in my main:
double a = 0;
ClassA classA;
classA.Method1(a);
This compiles fine. But when I move the Method1
implementation to a cpp file, like so...
Header:
class ClassA
{
public:
template<typename T>
void Method1(T&& a);
};
Implementation:
template<typename T>
void ClassA::Method1(T&& a) {}
template void ClassA::Method1<double>(double&&);
I receive the error message in Visual Studio 2013
error LNK2019: unresolved external symbol "public: void __thiscall ClassA::Method1(double &)" (??$Method1@AAN@ClassA@@QAEXAAN@Z) referenced in function _wmain
Now if in the main I replace the call to Method1
to
classA.Method1(std::move(a))
it compiles fine. Why does the header only version compiles fine without the std::move
whereas the version with the implementation requires a std::move
to compile?