Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!yale!cs.yale.edu!starr-page From: starr-page@CS.YALE.EDU (Page Starr) Newsgroups: comp.lang.c++ Subject: Re: An array of objects again! Message-ID: <15100@cs.yale.edu> Date: 10 Feb 90 13:10:08 GMT References: <1990Feb9.201223.14332@sdr.slb.com> Sender: news@cs.yale.edu Reply-To: starr-page@CS.YALE.EDU (Page Starr) Organization: Yale University Computer Science Dept, New Haven CT 06520-2158 Lines: 24 >(2) array of objects > Cell* pc = new Cell[N]; // null constructor. > for (int i = 0; i < N; i++) > pc[i] = *(new Cell(i)); // constructor with some argument. > You could consider: (2.0) array of objects Cell* pc = new Cell[N]; // null constructor. for (int i = 0; i< N; i++) new (pc[i]) Cell(i); // constructor with some argument. I believe the syntax is correct, but am not positive. This is known as in-place initialization, and avoids the creation of temporaries. -Page ----------------------------------------------------------------------------- Charismatic Services for you and me. ----------------------------------------------------------------------------- CSnet: starr@cs.yale.edu BITNET: starr@yalecs.BITNET ARPAnet: starr%cs.yale.edu@relay.cs.net Phone: (203)432-1215 USmail: Page Starr, Box 2158 Yale Station, New Haven, CT 06520