Overloaded triple valued function

I have an overloaded function that can take two types of arguments: int and double . When I evaluate it using a tee that can return either int or double , it always uses the double version. Why is this?

 #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; } 
+5
source share
1 answer

The ternary operator always does type advancement (into one type). So, if one result is int and the other is double, the result? the operator will always be double.

+8
source

Source: https://habr.com/ru/post/1209894/


All Articles