Overloading ambiguity: float and double : overloading ambiguity « Function « C++ Tutorial






#include <iostream> 
using namespace std; 
 
float f(float i); 
double f(double i); 
 
int main() 
{ 
  // unambiguous, calls f(double) 
  cout << f(10.1) << " "; 
 
  // ambiguous 
  //cout << f(10); // Error! 
 
  return 0; 
} 
 
float f(float i) 
{ 
  return i; 
} 
 
double f(double i) 
{ 
  return -i; 
}
-10.1








7.14.overloading ambiguity
7.14.1.Overloading ambiguity: float and double
7.14.2.Overloading ambiguity: char and unsigned char
7.14.3.Overloading abiguity: default parameter
7.14.4.Overloading a function - removing ambiguity with a cast