Files
2025-10-25 03:02:53 +03:00

2.4 KiB

[class.conv.general]

11 Classes [class]

11.4 Class members [class.mem]

11.4.8 Conversions [class.conv]

11.4.8.1 General [class.conv.general]

1

#

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

These conversions are calleduser-defined conversions and are used for implicit type conversions ([conv]), for initialization ([dcl.init]), and for explicit type conversions ([expr.type.conv], [expr.cast], [expr.static.cast]).

2

#

User-defined conversions are applied only where they are unambiguous ([class.member.lookup], [class.conv.fct]).

Conversions obey the access control rules ([class.access]).

Access control is applied after ambiguity resolution ([basic.lookup]).

3

#

[Note 1:

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

— end note]

4

#

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; // error: no viable conversion (a.operator X().operator int() not considered)int c = X(a); // OK, a.operator X().operator int() — end example]