There are two used-defined implicit conversion chains .
First - class -> bool -> no conversion
Second - class -> int -> bool
n3337 4/2
Note: expressions with the given type will be implicitly converted to other types in several contexts:
- When using the if statement or iteration in a condition (6.4, 6.5). The destination type is bool.
n3337 4/3
The effect of either an implicit conversion is the same as performing a declaration and initialization, and then using a temporary variable as a result of the conversion.
Quotes mean that really
if (class_var)
is an
if (bool _ = class_var)
n3337 13.3.3 / 1
Given these definitions, a viable function F1 is defined as a better function than another viable function F2, if for all arguments i, ICSi (F1) is not a worse transformation sequence than ICSi (F2), and then
- the context is initialization by user conversion (see 8.5, 13.3.1.5 and 13.3.1.6) and the standard conversion sequence from the return type F1 to the destination type (i.e., the initialization type of the object) is a better conversion sequence than the standard conversion sequence from return type F2 to destination type. [Example:
struct A { A(); operator int(); operator double(); } a; int i = a;
- end of example
So, the compiler should choose operator bool , since class -> bool -> no standart conversion better than class -> int -> standard conversion to bool
source share