Implicit conversions
Implicit conversions
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:
- when the expression is used as the argument when calling a function that is declared with
T2
as parameter; - when the expression is used as an operand with an operator that expects
T2
; - when initializing a new object of type
T2
, includingreturn
statement in a function returningT2
; - when the expression is used in a
switch
statement (T2
is integral type); - when the expression is used in an
if
statement or a loop (T2
isbool
).
The program is well-formed (compiles) only if there exists one unambiguous implicit c