Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Simple example results Message-ID: <70774@microsoft.UUCP> Date: 19 Feb 91 17:37:34 GMT References: <1991Feb14.165716.14417@cc.ic.ac.uk> <604@taumet.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 29 In article <604@taumet.com> steve@taumet.com (Stephen Clamage) writes: |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". Sorry for the confusion! I intended to post a version where whatami() above was not commented out [I commented out the above line while double- checking my results] With the line commented back in, my original statements should hold. |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.) I agree. The appropriate reference is ARM section 12.7 page 294.