Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!aero!aerospace.aero.org!jordan From: jordan@aerospace.aero.org (Larry M. Jordan) Newsgroups: comp.lang.c++ Subject: Calling virtual functions INDIRECTLY from constructors Message-ID: <94876@aerospace.AERO.ORG> Date: 18 Dec 90 20:58:33 GMT Sender: news@aerospace.aero.org Reply-To: jordan@antares.UUCP (Larry M. Jordan) Organization: The Aerospace Corporation, El Segundo, CA Lines: 50 Should there also be a loss of "virtualness" when virtual member functions are called INDIRECTLY from a constructor? Consider the following: #include static void say(char *s) { printf("%s\n", s); } struct C0 { virtual void f() { say("C0 init"); } virtual void g() { f(); } C0() { g(); } }; struct C1 : C0 { virtual void f() { say("C1 init"); } virtual void g() { f(); } C1() { g(); } }; main() { C0 aC0; C1 aC1; } I was expecting: C0 init C1 init C1 init But got (from Zortech v2.1): C0 init C0 init C1 init This seems like an amazing sleight of hand. How do you suppose it's done? -- Larry Jordan