Path: utzoo!utgpu!news-server.csri.toronto.edu!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: <1991Apr29.172821.8591@dragon.wpd.sgi.com> Date: 29 Apr 91 17:28:21 GMT References: <1991Apr2.110623.22219@and.cs.liv.ac.uk> <20164@alice.att.com> <1991Apr18.005426.21863@dragon.wpd.sgi.com> <71952@microsoft.UUCP> Sender: news@dragon.wpd.sgi.com (CNews Account) Reply-To: pal@wpd.sgi.com Organization: Silicon Graphics, Inc. Lines: 25 In article <71952@microsoft.UUCP>, jimad@microsoft.UUCP (Jim ADCOCK) writes: |> In article <1991Apr18.005426.21863@dragon.wpd.sgi.com> pal@wpd.sgi.com writes: |> |X::X(int i) { |> | new (this) X; |> | // Whatever additional processing is desired |> |} |> |> I think this approach is generally a bad idea -- especially if the class |> has any base classes or any members that require construction. If so, |> this approach will result in any base classes being initialized twice, |> and any members being initialized twice. An excellent point. Quite apart from the efficiency issues of double initialization, there would be only a single destructor called, even though the constructor for the base classes or members would be called twice. This could result in serious problems (incorrect reference counts, failure to free memory, etc.) Accordingly, I would withdraw my suggestion, and advise against using placement syntax on operator new() as a method of factoring out common initialization. -- Anil A. Pal, Silicon Graphics, Inc. pal@wpd.sgi.com (415)-335-7279