#include <iostream>
using namespace std;
int square(int x);
float square(float x);
int main() {
cout<<square(3);
cout<<square(3.14);
return 0;
}
int square(int x) {
cout<<"\nINT version called\n";
return x*x;
}
float square(float x) {
cout<<"\nFLOAT version called\n";
return x*x;
}
I have tried to replace the float version of a function with double one, and it starts to work then. What is the problem here? Cannot 3.14 be considered as float?
error: call of overloaded 'square(double)' is ambiguous
note: candidates are:
note: int square(int)
note: float square(float)