C++ implicit conversions

I think the answer from sharptooth is precise. The C++ Standard (SC22-N-4411.pdf) section 12.3.4 titled ‘Conversions’ makes it clear that only one implicit user-defined conversion is allowed.

1 Type conversions of class objects can be specified by
constructors and by conversion
functions. These
conversions are called user-defined conversions and are used
for implicit type conversions (Clause
4), for
initialization (8.5), and for explicit type conversions (5.4,
5.2.9).

2 User-defined conversions are applied only where they are
unambiguous (10.2, 12.3.2).
Conversions obey the
access control rules (Clause 11). Access control is applied after
ambiguity resolution (3.4).

3 [ Note: See 13.3 for a discussion of the use of conversions
in function calls as well as examples
below. —end
note ]

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

Leave a Comment