[class.conv.general] (original) (raw)

11 Classes [class]

11.4 Class members [class.mem]

11.4.8 Conversions [class.conv]

11.4.8.1 General [class.conv.general]

Type conversions of class objects can be specified by constructors and by conversion functions.

[Note 1:

See [over.match] for a discussion of the use of conversions in function calls as well as examples below.

— _end note_]

At most one user-defined conversion (constructor or conversion function) is implicitly applied to a single value.

[Example 1: struct X { operator int();};struct Y { operator X();}; Y a;int b = a; int c = X(a); — _end example_]

User-defined conversions are used implicitly only if they are unambiguous.

A conversion function in a derived class does not hide a conversion function in a base class unless the two functions convert to the same type.

Function overload resolution ([over.match.best]) selects the best conversion function to perform the conversion.

[Example 2: struct X { operator int();};struct Y : X { operator char();};void f(Y& a) { if (a) { } } — _end example_]