Note that this is different from direct initialization ( T2 t (e )), where explicit constructors and conversion functions would additionally be considered. Note: in arithmetic expressions, the destination type for the implicit conversions on the operands to binary operators is determined by a separate set of rules: usual arithmetic conversions.Ī user-defined conversion consists of zero or one non-explicit single-argument converting constructor or non-explicit conversion function call.Īn expression e is said to be implicitly convertible to T2 if and only if T2 can be copy-initialized from e, that is the declaration T2 t = e is well-formed (can be compiled), for some invented temporary t. If there are multiple overloads of the function or operator being called, after the implicit conversion sequence is built from T1 to each available T2, overload resolution rules decide which overload is compiled. The program is well-formed (compiles) only if there exists one unambiguous implicit conversion sequence from T1 to T2. when the expression is used in an if statement or a loop ( T2 is bool).when the expression is used in a switch statement ( T2 is integral type).when initializing a new object of type T2, including return statement in a function returning T2. when the expression is used as an operand with an operator that expects T2.when the expression is used as the argument when calling a function that is declared with T2 as parameter.Implicit conversions are performed whenever an expression of some type T1 is used in context that does not accept that type, but accepts some other type T2 in particular:
0 Comments
Leave a Reply. |