I'm trying to port some code from VC9 to G++, however Ive run into a problem with template specialisations apparently not being allowed for class members.
The following code is an example of these errors for the getValue specialisations of the class methods. In all cases the error is "error: explicit specialization in non-namespace scope class ...
"
template<typename T> T getValue(const_iterator key)const
{
try{return boost::lexical_cast<T>(key->second);}
catch(boost::bad_lexical_cast &e)
{
throw TypeParseError<T>(name, key->first, e.what());
}
}
template<typename T> T getValue(const std::string &key)const
{
iterator i = find(key);
if(i == end())throw KeyNotFound(name,key);
else return getValue(i);
}
template<> std::string getValue<std::string>(const_iterator key)const
{
return key->second;
}
template<> std::string getValue<std::string>(const std::string &key)const
{
const_iterator i = find(key);
if(i == end())throw KeyNotFound(name,key);
else return i->second;
}
Is it just the exact syntax is not supported, and that a minor change will make it work, or will I need to change the code to avoid specialisations like this? If the latter which is the best way to do so in general?