Explicit ctors

D

Dave

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top