Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Constructor question Message-ID: <676@taumet.com> Date: 19 Apr 91 15:27:35 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> Organization: Taumetric Corporation, San Diego Lines: 22 haydens@natasha.juliet.ll.mit.edu (Hayden Schultz) writes: >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... >class P { ... P(int i); ... }; >class C : public P { ... }; >P::P(int i) { > this = new C; >} This seems like a poor idea (it's not nice to fool the compiler), and will not work in general. If the object were not created with 'new', the object would appear to have two addresses, depending on what code was being exectued. In any event, the compiler will have the wrong idea about the size of the object. Finally, assigning to 'this' is an obsolescent feature, and will not be supported at some time in the future. -- Steve Clamage, TauMetric Corp, steve@taumet.com