Content deleted Content added
mNo edit summary |
|||
Line 37:
====C++====
In [[C++]] there are conditional assignment situations where use of the ''if-else'' statement is not possible, since this language explicitly distinguishes between [[initialization]] and [[assignment]]. In such case it is always possible to use an inline function call, but this is cumbersome and inelegant. Use of the ?: operator is much better whenever possible. For example, if you want to pass conditionally different values as an argument for a constructor of a field or a base class, it is not possible to use a plain ''if-else'' statement; in this case we can use a conditional assignment expression, or a function call. Mind also that some types allow initialization, but do not allow assignment, or even the assignment operator does totally different things than the constructor. The latter is true for reference types, for example:
<source lang="c">
#include <iostream>
|