Overloading abiguity: default parameter : overloading ambiguity « Function « C++ Tutorial






#include <iostream> 
using namespace std; 
 
int f(int i); 
int f(int i, int j=1); 
 
int main() 
{ 
  cout << f(4, 5) << " "; // unambiguous 
  //cout << f(10); // Error, ambiguous!  
 
  return 0; 
} 
 
int f(int i) 
{ 
  return i; 
} 
 
int f(int i, int j) 
{ 
  return i*j; 
}
20








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