I am getting compiler error of overloaded function is ambiguous. although i understand what it means but how to resolve this problem?
#include <iostream>
using namespace std;
int area(int );
int area(int ,int );
float area(float );
int main()
{
cout << "square: " << area(5) << "\n";
cout << "rectangle: " << area(22,14) << "\n";
cout << "circle: " << area(6.5) << "\n";
return 0;
}
inline int area(int a)
{
return (a*a);
}
inline int area(int b,int c)
{
return (b*c);
}
float area(float d)
{
return (3.14*d*d);
}
This is because
6.5
is adouble
not a float, the compiler then tries to findarea(double)
which doesn't exist. It's ambiguous betweenarea(float)
andarea(int)
.One solution is that you should call it using
6.5
as a float.area(6.5f)