Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!zaphod.mps.ohio-state.edu!mips!sgi!shinobu!odin!sgihub!dragon!xanadu.wpd.sgi.com!pal From: pal@xanadu.wpd.sgi.com (Anil Pal) Newsgroups: comp.lang.c++ Subject: Re: Constructor question Message-ID: <1991Apr15.164435.17867@dragon.wpd.sgi.com> Date: 15 Apr 91 16:44:35 GMT References: <1991Apr2.110623.22219@and.cs.liv.ac.uk> <20164@alice.att.com> <17400@sunquest.UUCP> <20204@alice.att.com> Sender: news@dragon.wpd.sgi.com (CNews Account) Reply-To: pal@wpd.sgi.com Organization: Silicon Graphics, Inc. Lines: 35 Cc: ark@alice.att.com In article <20204@alice.att.com>, ark@alice.att.com (Andrew Koenig) writes: |> |> The original question was whether it was possible for one constructor |> of a class to call another constructor to help it construct the |> same object; the answer to that question is `no.' How about calling operator new using the placement syntax (and placing the object at "this")? Thus: MyClass::MyClass(/* some parameters */) { // first call basic constructor new (this) MyClass(/* other parameters */); // Then do stuff specific to this constructor ... } On reading the ARM, it appears that one must define an appropriate operator new in order to use placement syntax. This is fairly trivial in this case: void* operator new(size_t, void* p) { return p; } I had originally thought that the pre-defined global operator new included placement syntax, but the ARM indicates that I am mistaken. Is there a reason why the definition above could (or should) not be included in the language? -- Anil A. Pal, Silicon Graphics, Inc. pal@wpd.sgi.com (415)-335-7279