auto x = new auto('a');
will do type deduction based on
T x = e;
I'm assuming that means it would use the copy constructor to deduce
the type, but does it use the copy constructor to actually initialize
the variable, or will it then use the default constructor?
Also, does specifying one (or both) of those constructors as explicit
effect the auto deduction?
Thanks!
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
There's an argument. Why would it use the default constructor?
>
> Also, does specifying one (or both) of those constructors as explicit
> effect the auto deduction?
No. Explicit only has an effect on conversions, not on copying, and
making the default constructor explicit is not possible. (That is, you
can make a constructor that can be called with both zero and one
arguments explicit, but it has no effect on the zero-argument use.)
> > I'm assuming that means it would use the copy constructor to deduce
> > the type, but does it use the copy constructor to actually initialize
> > the variable, or will it then use the default constructor?
>
> There's an argument. Why would it use the default constructor?
Sorry, my bad wording - let me rephrase. If the type is deduced by the
copy constructor, is it guaranteed that the copy constructor will be
used
to initialise the variable, or might any other fitting constructor be
used?
E.g., for
auto x = new auto('a');
type deduction based on:
T x = e
but
T x(e)
used for actual initialization?