"Ambiguous template specialization" problem
- by Setien
I'm currently porting a heap of code that has previously only been compiled with Visual Studio 2008.
In this code, there's an arrangement like this:
template <typename T>
T convert( const char * s )
{
// slow catch-all
std::istringstream is( s );
T ret;
is >> ret;
return ret;
}
template <>
inline int convert<int>( const char * s )
{
return (int)atoi( s );
}
Generally, there are a lot of specializations of the templated function with different return types that are invoked like this:
int i = convert<int>( szInt );
The problem is, that these template specializations result in "Ambiguous template specialization".
If it was something besides the return type that differentiated these function specializations, I could obviously just use overloads, but that's not an option.
How do I solve this without having to change all the places the convert functions are called?