template linker error
This is how the overloaded operator looks like...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//.h
template<class T>
Value& operator>>( Value& v, T& type );
//.cpp
template<class T>
Value& operator>>( Value& v, T& type )
{
if(!v.m_data.size()) return v;
Value::Data* temp = v.m_data.at(v.m_data.at(v.m_data.size()-1));
type = *temp;
delete temp;
v.m_data.pop_back();
return v;
}
|
And here's how I use it..
1 2 3
|
Value v(12);
std::string a;
v >> a;
|
But I get a linker error.. :|
visual studio:
error LNK2019: unresolved external symbol "class Value & __cdecl operator>>
<class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > >(class Value &,class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &)" (??$?5V?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@@YAAAVValue@@AAV0@AAV?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
|
mingw:
undefined reference to `Value& operator>><std::string>(Value&, std::string&)'|
|
What am I doing wrong ?
you need to put everything in the header when using templates
oh.. did not know that.. good to know. Thanks :D
Topic archived. No new replies allowed.