Xref: utzoo gnu.g++.help:451 comp.lang.c++:11535 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!CUNYVM.CUNY.EDU!chatty%FRLRI61.BITNET From: chatty%FRLRI61.BITNET@CUNYVM.CUNY.EDU Newsgroups: gnu.g++.help,comp.lang.c++ Subject: 'this' in member initialization Message-ID: <9102080900.AA19725@lri.lri.fr> Date: 8 Feb 91 09:00:21 GMT Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.g++.help Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu Lines: 41 // the following program is accepted by both g++ and cfront 2.0. // It leads to the suprising thing that a virtual method of class B is // called before the body of the constructor is entered. // I think ARM, p47, s5.1, forbids the use of 'this' in member // initialization. // any comments? extern "C" void printf (const char*, ...); class A { public: A () {} virtual void foo () {printf ("A::foo\n");} }; class Z { public: Z (A* a) {a->foo ();} }; class B : public A { public: Z z; B () : A (), z (this) {printf ("B::B\n");} // legal?! void foo () {printf ("B::foo\n");} }; main () { B b; } // % a.out // B::foo // B::B Stephane Chatty chatty@lri.lri.fr, chatty@frlri61.bitnet