"Ambiguous template specialization" problem

Posted by Setien on Stack Overflow See other posts from Stack Overflow or by Setien
Published on 2010-05-15T16:36:15Z Indexed on 2010/05/15 16:44 UTC
Read the original article Hit count: 258

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about gcc

Related posts about templates