Explicit ctors



 DEVELOP > c-Plus-Plus > Explicit ctors

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "Dave"
Date: 26 Nov 2003 03:36:00 PM
Object: Explicit ctors
Hello all,
1.
I am able to declare as explicit ctors that cannot take exactly one
argument - they either take fewer (default ctor) or more arguments. What is
the significance of declaring such ctors explicit?
Speaking specifically of default ctors, I find the following in the
Standard:
12.3.1/2: "A default constructor may be an explicit constructor; such a
constructor will be used to perform default-initialization (8.5)."
Unfortunately, this doesn't help clarify the situation for me with regard to
default ctors, and, of course, it doesn't speak at all to ctors that must
take more than one argument.
2.
Why would one ever want to designate a copy ctor as being explicit?
The purpose of explicit ctors is to inhibit implicit conversions. How does
that come into play when dealing with copy ctors? How would you ever have
an "implicit conversion" to the class type of which you already are?
Designating a copy ctor as explicit seems to inhibit only the following:
a. Variable definitions such as: foo_t a = b; (Note that "foo_t a(b);" is
OK.)
b. Returning an object by value; (Note that *passing* it by value seems to
be OK however.)
Thanks,
Dave
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER