why we need type casting for float in function overloading

anand_kr_sin's Avatar, Join Date: Nov 2011
Newbie Member
The function was like
Code:
class calc
{
float area(float a)
{
    return a*a;
}
int area(int a)
{
return a*a;
}
};
main()
{
calc ob1;
ob1.area(10);
ob1.area(10.5);
getch();
}

Last edited by shabbir; 30Nov2011 at 15:10.. Reason: Code blocks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Because
Code:
int foo(int bar)
{
...
}

int quux()
{
  foo(10.5);
}
is legal, so the compiler doesn't know if the second call to area() is to area(int(10.5)) or area(float). The cast removes the ambiguity.