Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!sbi!pivot-sts!swampthing!wfl From: wfl@swampthing.sbi.com (W. Linke CPE) Newsgroups: comp.lang.c++ Subject: Re: Pure virtual destructors are illegal? Summary: pure virtuality is an ill-defined concept Keywords: virtual destructor Message-ID: <188@swampthing.sbi.com> Date: 4 Jun 91 23:34:38 GMT References: <183@swampthing.sbi.com> <1991Jun1.192610.18321@borland.com> <1991Jun4.134034.21404@world.std.com> Organization: Salomon Brothers - NJ Lines: 45 In article <1991Jun4.134034.21404@world.std.com>, wmm@world.std.com (William M Miller) writes: > ordinary member functions. Specifically, a pure virtual member function > "*MUST* be defined" if it is ever invoked; constructors are guaranteed to be Actually a virtual member function must be defined if an object of its class is created; the function doesn't need to be invoked. (If pointers to member functions are used, it may not be possible for the compiler to know whether a particular function will be invoked.) The following program fails to link, because there's no function f defined for the vtbl to point to: class A { public: virtual void f(); }; main() { A a; } Pure virtual functions work the same way, subject to derivation to a non-abstract class. Note that section 10.3 of the ARM, which talks about undefined results from calling a pure virtual function, does so only in reference to calling the function from within a *constructor*, because (I presume) the vtbl might not be initiallized with derived class data yet. It doesn't say the function needn't be defined. > invoked. Similarly, a derived class whose base has a destructor is provided > a destructor by the compiler if none is explicitly coded, thus implicitly > overriding a virtual destructor in the base class. > > Pure virtual works exactly the same in both cases; there are no special > rules for pure virtual destructors, just interactions between rules. Well, I agree there's no inconsistency, but destructors are a special case of member function in that the compiler itself generates direct calls to base class destructors, and that specialness shows through the rules to such an extent that (for instance) C++ textbooks would be better advised to break up the topic into "PV Destructors" and "PV Non-destructors" instead of lumping them together, because the implications of all the rules aren't obvious. (V Destructors and V Non-destructors are different enough to merit this, also.) Then I wouldn't have to waste bandwidth to get educated! :-) Bill Linke uunet!sbi!gort!wfl