I have an overloaded function which can take two argument types : int
and double
. When I evaluate it with a ternary which can return either an int
or a double
, it always uses the double
version. Why is that?
#include<iostream>
using namespace std;
void f(int a)
{
cout << "int" << endl;
}
void f(double a)
{
cout << "double" << endl;
}
int main()
{
string a;
cin >> a;
f(a=="int" ? 3 : 3.14159);
return 0;
}