I can't understand why function call 6 can't call def#3.isn't their type the same?Code:#include<iostream> using namespace std; void f1() {cout << "overload def#1 of f1()" << endl;} // def#1 void f1(int x) {cout << "overload def#2 of f1()" << endl;} // def#2 void f1(double x) {cout << "overload def#3 of f1()" << endl;} // def#3 void f1(double x, char y) {cout << "overload def#4 of f1()" << endl;} // def#4 void f1(int x, char y) {cout << "overload def#5 of f1()" << endl;} // def#5 void f1(double &x) {cout << "overload def#6 of f1()" << endl;} // def#6 int main() { /*1.*/ f1(2); /*2.*/ f1(); /*3.*/ f1(2.5, 'A'); /*4.*/ f1(2, 'A'); double a = 2.5; /*5.*/ f1(2.5); /*6.*/ f1(a); return 0; } // end main()
and if comment the function call at 6 i give default value to parameter x of def#2 ,it will be error function call 2.
can someone explain to me how is it ambiguous?. or give me the chapter name so i can go re-study.
at least give me a hint before i got more misunderstanding.
sorry for my english.




Reply With Quote
