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?
int
double
#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; }
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.
Source: https://habr.com/ru/post/1209894/More articles:Portable "type" of a name with external communication - c ++Getting SSDP response using CocoaAsyncSocket in Swift - iosShow u8 fragment in hexadecimal notation - sliceThe parseInt (1/10000000) function returns 1. Why? - javascriptTesting the line order of text on a web page - Rspec & Capybara on rails - ruby-on-railshttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1209895/windows-application-that-optionally-writes-to-a-console-in-c&usg=ALkJrhjsGurrHKzepIBpyoQ-Ha4t_g162AToo many elements in the structure initializer - c ++Creating a mutable collection from immutable - javaFull screen iOS background image for all screen sizes - iosCoin Exchange Algorithm - javaAll Articles