This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: ISO C++ forbids initialization in array new?
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: WU Yongwei <wuyongwei at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 19 Aug 2005 09:19:55 +0100
- Subject: Re: ISO C++ forbids initialization in array new?
- References: <8eeef57f05081820394d7b3b62@mail.gmail.com>
WU Yongwei wrote:
> Well, I see this in the gcc error message. Can someone here kindly
> point to me which part of the Standard specified this behaviour? I
> thought it should be in 5.3.4, but was not able to find the words
> there.
It might be better if the error message said "non-default
initialization" since default initialization is allowed (and required).
I assume you are trying something like this:
int* i = new int[5](23);
A new initializer must have the form (...) (see 5.3.4/1) and the only
way that can be used to initialize an array is for default construction.
This is OK, and default initialises the array, which default initialises
each element (8.5/5)
int* i = new int[5]();
but this is not OK:
int* i = new int[5](23);
because it is not valid to initialise an array like this:
typedef int (five_ints)[5];
five_ints i(23);
this gives:
array_init.cc:8: error: cannot initialize arrays using this syntax
HTH
jon
--
sigfault