I know I'm missing something easy here but I've got a templated member function of a class which I've specialised.
class MyClass
{
template<typename T> T GetTFromVariable(shared_ptr<TOtSimpleVariable> v, string s);
}
template<typename T>
T MyClass::GetTFromVariable(shared_ptr<TOtSimpleVariable> v, string s)
{
throw std::runtime_error("Don't know how to convert " + ToString(v->GetString()));
}
template<>
int MyClass::GetTFromVariable<int>(shared_ptr<TOtSimpleVariable> v, string s)
{
return v->GetInteger();
}
template<>
string MyClass::GetTFromVariable<string>(shared_ptr<TOtSimpleVariable> v, string s)
{
return v->GetString();
}
// etc for other specialisations.
This is defined in my header file (as templates should be) but when I go to compile, I get a bunch of multiple defined symbols errors, such as:
OtCustomZenith_logic.lib(PtPathOutput.obj) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall MyClass::GetTFromVariable<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class boost::shared_ptr<class TOtSimpleVariable>,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??$GetTFromVariable@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@CommandProperties@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$shared_ptr@VTOtSimpleVariable@@@boost@@V12@@Z) already defined in TableFareSystem_test.obj
I can fix it by inlining the method but I don't think that should be necessary... what am I missing?
EDIT: I'm using Visual Studio 2010