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?