Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!herald.usask.ca!alberta!ubc-cs!uw-beaver!mit-eddie!mintaka!olivea!uunet!mcsun!ukc!icdoc!cc.ic.ac.uk!rb From: rb@cc.ic.ac.uk (Robin Becker) Newsgroups: comp.lang.c++ Subject: Simple example results Message-ID: <1991Feb14.165716.14417@cc.ic.ac.uk> Date: 14 Feb 91 16:57:15 GMT Organization: Imperial College Computer Centre Lines: 68 Originator: rb@cc.ic.ac.uk Nntp-Posting-Host: suns1cc Someone posted the following simple inheritance example recently here are the results from TC++ and Zortech 2.1 extern "C" { #include } class base { public: virtual void whatami() { printf("I'm a base.\n"); } base() { printf("In the base constructor "); whatami(); } ~base() { printf("In the base destructor "); whatami(); } }; class derived : public base { public: /* virtual void whatami() { printf("I'm a derived.\n"); } */ derived() { printf("In the derived constructor "); whatami(); } ~derived() { printf("In the derived destructor "); whatami(); } }; class mostderived : public derived { public: virtual void whatami() { printf("I'm a mostderived.\n"); } mostderived() { printf("In the mostderived constructor "); whatami(); } ~mostderived() { printf("In the mostderived destructor "); whatami(); } }; main() { mostderived object; return 0; } should print according to the poster: In the base constructor I'm a base. In the derived constructor I'm a derived. In the mostderived constructor I'm a mostderived. In the mostderived destructor I'm a mostderived. In the derived destructor I'm a derived. In the base destructor I'm a base. If it doesn't -- call your compiler vendor and complain. Zortech (compiled with ztc -g test.cpp) In the base constructor I'm a base. In the derived constructor I'm a base. In the mostderived constructor I'm a mostderived. In the mostderived destructor I'm a mostderived. In the derived destructor I'm a mostderived. In the base destructor I'm a mostderived. TC++ (Academic version only using default settings) In the base constructor I'm a base. In the derived constructor I'm a base. In the mostderived constructor I'm a mostderived. In the mostderived destructor I'm a mostderived. In the derived destructor I'm a base. In the base destructor I'm a base. What can one say? Who is right? Is symmetry important?