In C++, an implicit conversion takes place when passing a type T1
when a type T2
is expected. It can happen in many places like function calls, switch
statements, if
statements, etc.
Implicit conversion sequence follows this order:
- Zero or one standard conversion
- Zero or one user-defined conversion
- Zero or one standard conversion, only if a user-defined conversion was used.
A user-defined conversion is a non-explicit constructor of type T2
taking a type T1
or T1
has a non-explicit conversion operator to T2
. The former is called a converting constructor.
A standard conversion consists of the following, in this order:
- zero or one conversion from the following set:
- lvalue-to-rvalue conversion,
- array-to-pointer conversion, and
- function-to-pointer conversion;
- zero or one numeric promotion or numeric conversion;
- zero or one function pointer conversion; (since C++17)
- zero or one qualification conversion.