🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #468

'this' in member initialization

#468
From: chatty%FRLRI61.BITNET
Date: Fri, 08 Feb 1991 09:00
41 lines
1295 bytes
// 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
Technical Details
Message-ID: <9102080900.AA19725@lri.lri.fr>
Path: arc1-ca.pugleaf.net!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

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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