I have an issue with template specialization which I would like to understand. I'm working with Visual C++ 10.0 (2010). I have a class like this:
class VariableManager
{
public:
template<typename VarT>
VarT get(std::string const& name) const
{
// Some code...
}
// This method supposed to be fully evaluated, linkable method.
template<>
std::string get<std::string>(std::string const& name) const;
private:
std::map<std::string, boost::any> mVariables;
};
In theory, because I specialized the "get" method, the linker should be able to pick up from an object file. Instead, I get an unresolved reference error with the linker if I place the method in the source file:
template<>
std::string VariableManager::get<std::string>(std::string const& name) const
{
// Doing something...
}
If I place this method in the header file as inline, the build goes just fine. I do understand that template functions as this:
template<typename VarT>
VarT get(std::string const& name) const;
should be placed in the header because the compiler won't be able to specialize the template according to the calling code, but in the case of full specialization it is the class' implementation that does that thus the specialized template method should already exist as a public symbol. Could somebody throw some light on this issue?