Topic: Question about new auto(x)


Author: CornedBee <wasti.redl@gmx.net>
Date: Tue, 3 Nov 2009 12:26:59 CST
Raw View
On Nov 2, 4:10 am, "george.r...@gmail.com" <george.r...@gmail.com>
wrote:
> Looking at N2960, 5.3.4 para 2 states that
>
> 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?

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.)


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





Author: "george.ryan@gmail.com" <george.ryan@gmail.com>
Date: Wed, 4 Nov 2009 22:57:00 CST
Raw View
On Nov 3, 2:26 pm, CornedBee <wasti.r...@gmx.net> wrote:

> > 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?





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





Author: "george.ryan@gmail.com" <george.ryan@gmail.com>
Date: Sun, 1 Nov 2009 21:10:44 CST
Raw View
Looking at N2960, 5.3.4 para 2 states that

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-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]