Article View: comp.std.c++
Article #3014can initialization be used with new[]?
From: Lassi A. Tuura
Date: Tue, 16 Jan 1996 10:17
Date: Tue, 16 Jan 1996 10:17
40 lines
1922 bytes
1922 bytes
One compiler I need to use has problems with the following code:
---------------
#include <new.h>
class T {
public:
T (int n) : _n (n) { }
T (const T &ref) : _n (ref._n) { }
~T () { }
private:
int _n;
};
void f ()
{
T *ptr = new T [10] (1); // line 14
}
---------------
In particular, it complains about the initializer to the vector new:
CC: "test.cc", line 14: error: initializer for array of class object
created using `new' (1248)
Another compiler has no problems with the code, and the one giving the
error message has not proved to be reliable. The question is: Is this
legal C++? I read thru 5.3.4 from the april draft and as far as I
understood the code was flagged ill-formed. Did I interpret the draft
correctly? If I did, how am I supposed to allocate an array of
objects of class T? With explicit calls to operator new and placement
new?
BTW, is either comp.lang.c++.moderated or comp.std.c++ archived
somewhere? I recall I have read something about this matter some time
back.
//LaT
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<l8291j9wix9.fsf@neppari.cs.hut.fi>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backShow Full Headers
Complete Article Headers
From: "Lassi A. Tuura" <Lassi.Tuura@hut.fi> Message-ID: <l8291j9wix9.fsf@neppari.cs.hut.fi> X-Original-Date: 15 Jan 1996 17:56:34 +0200 Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 16 Jan 96 10:17:43 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: can initialization be used with new[]? Organization: Helsinki University of Technology, Finland Reply-To: Lassi.Tuura@hut.fi X-Newsreader: Gnus v5.1 X-Disclaimer: This message represents at most my opnions X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMPt/DOEDnX0m9pzZAQHVAAGAkRzyMC0S6KFH/bbI6P3nVZ54dL21011D cQWluJ2rd02zmucddFrpSO6/ntpj0UFq =273G