I cannot understand why inside my main() the function myfunct(i) is ambiguous? I got the code from a book. I run the code(to some free IDE) and the error i get says: ambiguous.
The book explains it: inside the main(), 'i' value , if it converts to an other data type (char, long double,float,long int) it will fit with more than one versions of the same function. Huh??Why? I thought it was possible this:
int i ---convert to---> long int...
Rules of overloading(brielfy, not everything):
possible 'upgrades':
-unsigned char,short int,bool 'upgrade' to int.
- float 'upgrades' to double.
data type conversions follow up.(if 'upgrades' cannot help enough).Eg int->long int,int->float,double->long double, double->bool and more....
i looked wiki, but in vain.... :-(
rules of function overloading: If you could enlighten me with a good tutorial,to the point( not too much bla bla) and easy to grasp it, i would appreciate it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <cstdlib>
void myfunct(long double a);
void myfunct(long int a);
void myfunct(float a);
void myfunct(char a);
using namespace std;
int main(int argc, char *argv[])
{
int i=8;
//myfunct(i);
cout << myfunct(i);
cout << "\n\n";
system("pause");
}
// the following code is not in the book, i added it now.
void myfunct(long double x){
cout << x;
}
void myfunct(long int x){
cout << x;
}
void myfunct(float x){
cout << x;
}
void myfunct(char x){
cout << x;
}
|
Thanks...