🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by chatty%FRLRI61.BITNET Fri, 08 Feb 1991 09:00
'this' in member initialization
#468
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads