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?


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.

Need Your Help

Smoothly invertible additive/subtractive luminance blending in OpenGL

opengl alphablending blending pyopengl

I'm trying to perform a rather specific blending operation, but one that seems like it ought to be relatively simple. I'm displaying a luminance texture on top of a background with an alpha value o...

how to install Open CV for Python 3.x in windows 8.1?

python opencv numpy cmake

I am trying to install and run OpenCV 3.0.0 for python 3.4.2, in windows 8.1

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.