Andrea Casaccia
Andrea Casaccia

Reputation: 4971

Why is this call to overloaded function ambiguous?

I am a beginner in template programming and I am using the following template function trying to avoid code duplication:

template <class T>
void foo(T iInteger) {

    // ... same algorithm for all integer types

    std::to_string( static_cast<T>(iInteger) ); // C2668: ambiguous call to overloaded function

    // ... end of algorithm

}

My foo function will be called only with primitive integral types. I was naively thinking that static_cast would have been enough to tell the compiler which overload of std::to_string() to use, but this seems not enough as im still getting a C2668: ambiguous call to overloaded function. What am I missing? Is it possible to avoid duplicating the same code for all primitive integer types while still calling the appropriate std::to_string overload?

Upvotes: 2

Views: 5146

Answers (1)

Andrea Casaccia
Andrea Casaccia

Reputation: 4971

As pointed out by chris in the comments to the question, the problem is that I'm using VS2010, which does not fully implement the c++11 standard. std::to_string implements only overloads for long long, unsigned long long, long double. See this related question for more details on the matter.

Upvotes: 2

Related Questions