Topic: Explicit vs. Ambiguous
Author: Biju Thomas <b_thomas@ibm.net>
Date: 1999/10/27 Raw View
Bill Wade wrote:
>
> Are explicit constructors considered during overload resolution in
> "implicit" situations?
>
> struct T
> {
> explicit T(double);
> T(float);
> };
>
> T t = 5; // Ambiguous?
No, it is not ambiguous.
Explicit constructors are not converting constructors by 12.3.1 para 1
of the standard. And, by 13.3.1.4 para 1, only converting constructors
are to be used for overload resolution when copy-initialization is
involved.
--
Biju Thomas
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@eng.sun.com (Steve Clamage)
Date: 1999/10/27 Raw View
"Bill Wade" <bill.wade@stoner.com> writes:
>Are explicit constructors considered during overload resolution in
>"implicit" situations?
No. You must write an explict type conversion for an
'explicit' constructor to be considered.
>struct T
>{
> explicit T(double);
> T(float);
>};
>T t = 5; // Ambiguous?
No. It should be treated as
T t = T(5.0f);
--
Steve Clamage, stephen.clamage@sun.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Bill Wade" <bill.wade@stoner.com>
Date: 1999/10/24 Raw View
Are explicit constructors considered during overload resolution in
"implicit" situations?
struct T
{
explicit T(double);
T(float);
};
T t = 5; // Ambiguous?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]