Topic: explicit' constructor confusion


Author: "Bill Wade" <wrwade@swbell.net>
Date: Wed, 26 Sep 2001 17:04:50 GMT
Raw View
"max" <max@foobar.com> wrote

> I'm confused. I read both "The C++ Programming Language" and the C98 spec
on
> 'explicit' constructors. Neither the text nor the examples make it clear
if
> explicit constructors are errors if called implicitly, or if they simply
are
> not found during overload resolution. For example:
>
> struct X {
>     explicit X(int);
>     X(long);
> };
>
> X x = 5;
>
> Overload resolution gives us X(int) as the best match. But is it an error
> because X(int) is explicit, or is X(int) skipped and X(long) chosen?

This is copy initialization (8.5/12)
The converting constructors of X are considered (13.3.1.4)
Converting constructors are not 'explicit' (12.3.1/1)

So I'd say that X(int) is not considered.  Of course I've been wrong before.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "max" <max@foobar.com>
Date: Fri, 21 Sep 2001 16:50:29 GMT
Raw View
I'm confused. I read both "The C++ Programming Language" and the C98 spec on
'explicit' constructors. Neither the text nor the examples make it clear if
explicit constructors are errors if called implicitly, or if they simply are
not found during overload resolution. For example:

struct X {
    explicit X(int);
    X(long);
};

X x = 5;

Overload resolution gives us X(int) as the best match. But is it an error
because X(int) is explicit, or is X(int) skipped and X(long) chosen?


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]