//function overloading
#include <iostream>
using namespace std;
//declaration of function protype
int area(int);
int area(int, int);
float area(float);
int main()
{
cout << "calling the area() function for computiong the area of a square (side=5) - " << area(5) << "\n";
cout << "calling the area() function for computiong the area of a rectangle (length = 5, bredth = 10) - " << area(5, 10) << "\n";
cout << "calling the area() function for computiong the area of a cirlce (radius 5.5) - " << area(5.5) << "\n";
return 0;
}
int area(int side)
{
return (side * side);
}
int area(int length, int breadth)
{
return (length * breadth);
}
float area(float radius)
{
return (3.14 * radius * radius);
}
error
program4_5.cpp: In function 'int main()':
program4_5.cpp:14:106: error: call of overloaded 'area(double)' is ambiguous
14 | cout << "calling the area() function for computiong the area of a cirlce (radius 5.5) - " << area(5.5) << "\n";
| ^
program4_5.cpp:6:5: note: candidate: 'int area(int)'
6 | int area(int);
| ^~~~
program4_5.cpp:8:7: note: candidate: 'float area(float)'
8 | float area(float);
| ^~~~
PS C:\Users\hasht\Desktop\coding\OOP with c++>
this code while compiling shows function overloading error but from what I know it's correct as I have defined the float area( float radius) function. Can anyone explain why this error occurs. I am new to coding and i don't know how to fix this.