Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!samsung!rex!wuarchive!zaphod.mps.ohio-state.edu!rpi!batcomputer!cornell!uw-beaver!mit-eddie!xn.ll.mit.edu!xn!haydens From: haydens@natasha.juliet.ll.mit.edu (Hayden Schultz) Newsgroups: comp.lang.c++ Subject: Re: Constructor question Message-ID: Date: 17 Apr 91 16:36:19 GMT References: <1991Apr2.110623.22219@and.cs.liv.ac.uk> <20164@alice.att.com> <17400@sunquest.UUCP> <20204@alice.att.com> <1991Apr15.164435.17867@dragon.wpd.sgi.com> Sender: usenet@xn.ll.mit.edu Organization: M.I.T. Lincoln Lab - Group 42 Lines: 46 In-Reply-To: pal@xanadu.wpd.sgi.com's message of 15 Apr 91 16:44:35 GMT >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: Why do you have to redefine the operator new? Here's a simple example which does it with a parent class and a derived child class. If there's no inheratance relationship, you could do the same thing if you created a conversion operator from C to P. include class P { int q; public: P() { q = 5; } P(int i); virtual void x() { cout << "parent class\n" << flush; }; }; class C : public P { public: void x() { cout << "child class\n" << flush; } }; P::P(int i) { this = new C; } main() { P p; p.x(); } Hayde Schultz (haydens@juliet.ll.mit.edu)