Is there any logical reason that will explain why in a triple optor, both branches must have the same base type or be convertible to one? What is the problem of the lack of this rule? Why can't I do this (this is not a good example, but it clarifies what I mean):
int var = 0; void left(); int right(); var ? left() : right();
Expressions must be of a type known at compile time. You cannot have expressions like "X or Y"; it must be one or the other.
Consider this case:
void f(int x) {...} void f(const char* str) {...} f(condition ? 5 : "Hello");
? , , , , . , , , .
, ( ).
. , .
, .
I think because the ternary operator must have a specific return value. It is difficult to do if the types of both branches are different or invalid.
Source: https://habr.com/ru/post/1785480/More articles:enter default values in Spring bean with annotation - javaiOS: pop-up menu does not behave according to the set of first responders - iosCan IIS 7 URL Rewrite Module rewrite outgoing HTML loaded via AJAX? - ajaxTFS Requirements Report Showing Incorrect Data - tfsDoes the Silverlight navigation template work with browser launch? - silverlightChrome freezes when using javascript to check for many checkboxes, while firefox does it instantly - javascriptКак использовать IIS 6 Web Deploy для развертывания на виртуальном пути, отличном от стандартного? - msbuildUPDATE where timestamp is last - sqlEasy timeout for CFWriteStreamWrite / CFReadStreamWriter? - iosdata compression - machine learning for exponential distribution - algorithmAll Articles