Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!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 again Message-ID: <1991Feb16.140407.24242@cc.ic.ac.uk> Date: 16 Feb 91 14:04:06 GMT Organization: Imperial College Computer Centre Lines: 73 Originator: rb@cc.ic.ac.uk Nntp-Posting-Host: suns1cc Thanks to those people who emailed me concerning this and pointed out that one of the whoami functions was commented out. I took the source directly from the net and as far as I can remember made no changes. I uncommented the whoami and retried; originally I was concerned that the two compilers gave such different results. They still do and I think that Zortech is wrong. 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: // this one was commented out 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 derived. 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 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. seems like ztc is doing something weird!