Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Simple example results Message-ID: <604@taumet.com> Date: 15 Feb 91 16:43:11 GMT References: <1991Feb14.165716.14417@cc.ic.ac.uk> Organization: Taumetric Corporation, San Diego Lines: 27 rb@cc.ic.ac.uk (Robin Becker) writes: >Someone posted the following simple inheritance example recently >here are the results from TC++ and Zortech 2.1 >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(); } >}; Since whatami is commented-out in class derived, there is no way to print the phrase "I'm a derived". Within the constructor or destructor for any class, virtual function calls can refer only to functions in the current or base classes, never to functions in any derived class. (In a constructor, the derived class doesn't exist yet, so you can't refer to its members. In a destructor, the derived class is gone, so you can't refer to its members.) For the code you show, Borland got it right, Zortech is wrong. -- Steve Clamage, TauMetric Corp, steve@taumet.com