- Joined
- Sep 22, 2008
- Messages
- 602
- Reaction score
- 2
- Points
- 0
Summary of what I've learned in this thread:
Original Post:
I'm having problems with template specializations:
The problem is that only the specialization get compiled. When I try to use the general case, I get 'error LNK2001: unresolved external symbol'.
I've also opened the generated object file, and the only symbol declared is the specialized function, but not the general case.
Using VC2008 BTW.
- A template class/method/function should be implemented in a header file to be included in every cpp file where it's needed. It can't be implemented in a separate cpp file (as you'd normally do for normal functions and methods), as the compiler need to know for which types it need to generate code for.
- NEVER ask questions if you're in need of a good night's sleep :thumbup:.
Original Post:
I'm having problems with template specializations:
Code:
class Test
{
template<class T> T get_value ();
};
template <class T> T Test::get_value ()
{
//Some code
}
template <> string Test::get_value ()
{
//Specialized code
}
Code:
Test a;
a.get_value<string> (); //Works
a.get_value<double> (); //Doesn't work
Using VC2008 BTW.
Last edited:
