This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: error: ISO C++ forbids initialization in array new


On Sat, May 15, 2004 at 01:48:39AM +0200, Maurizio Monge wrote:
> 
> Hello,
> I apologize if this is not the proper mailing list for my question.
> 
> the following code:
> 
>    int* b = new int[7](3);
> 
> Compiles on gcc-3.3.1 (unless -pedantic), but it alwais fails on gcc-3.4.
> I found nothing about it on manuals, has it been intentionally removed or 
> is this a bug in gcc-3.4?

It is a bug in your code; this is not valid C++.  There is no commitment
that gcc releases will continue to accept invalid code just because
previous gcc releases did.  3.4 has a new C++ parser that is much closer
to the ISO C++ standard than the old one.

For constructs of this sort, where you need to dynamically allocate an
array of objects initialized in the same manner, std::vector is a good
choice, e.g. instead of

	int* b = new int[size](value);

try

	std::vector<int> b(size, value);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]