Friday, 8 July 2016

What happens when float argument is passed to overloaded function with int and char as parameters(Type Conversion rules)?

Guess the output?


void PostInArrayNotFound(int a)
std::cout<<"Int is called"<<std::endl;

void PostInArrayNotFound(char a)
std::cout<<"Unsigned int is called"<<std::endl;

int main()
return 0;


It will give an compilation error.


There is no function with name “PostInArrayNotFound” and double as an argument.
I think, now compiler is in big tension, to call which “PostInArrayNotFound” function now?
Because float can be implicitly converted to any one of the integral type. Note carefully integral type can be char, unsigned char, int, unsigned int.

So because of this confusion, compiler will throw error on you like, call to the “PostInArrayNotFound” function is ambiguous.