+ 2
Please tell me what's happening here T~T
Take a look at my below code. https://code.sololearn.com/cPMK8lslJ1f7/?ref=app In this, the function findMin() returns the lowest of two parameters with the type of the lowest parameter. But, how the second output is of type double??? Thank you already :)
4 Antworten
+ 2
Rishi sorry, I'll edit it later
For the same reason it does that in the other case:
operators (such as ?: ) want their argument to be of the same type, to do that they compare the two types and decide which one is "stronger", and than they convert the "weak" one to that type
In your case double is stronger than int, so int gets converted to double and the overall type of the operator is double
+ 2
decltype is done at compile time,
that means it will never know the values of a and b, and it will consider just their types
What the compiler will see is:
decltype(bool? int : double) in the first case,
and
decltype(bool? double : int) in the second case
both cases will give decltype(double) by the rules of arithmetic conversion
0
Angelo I think the first and second case are reversed in your comment. How will the compiler give decltype(double) in the second case? (First case in your comment)
0
Angelo :O that's why my code is behaving so. Thank you, now this is solved for me :)