Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!world!wmm From: wmm@world.std.com (William M Miller) Newsgroups: comp.lang.c++ Subject: Re: Pure virtual destructors are illegal? Keywords: virtual destructor Message-ID: <1991Jun5.145047.8499@world.std.com> Date: 5 Jun 91 14:50:47 GMT References: <1991Jun1.192610.18321@borland.com> <1991Jun4.134034.21404@world.std.com> <188@swampthing.sbi.com> Organization: Glockenspiel, Ltd. Lines: 46 wfl@swampthing.sbi.com (W. Linke CPE) writes: > Actually a virtual member function must be defined if an object of its class > is created; the function doesn't need to be invoked. The circumstances under which a virtual function must be defined are under discussion by X3J16. E&S is not much help, as it doesn't address virtual functions specifically at all (see p. 14, "If a function is never called and its address is never taken, it need not be defined"). Existing practice differs, too, not necessarily reflecting your dictum. For example, class X { virtual void f(); virtual void g(); }; void X::f() {} int main() { return 0; } This program links just fine under Zortech 2.12 and Borland Turbo C++ 1.0, but it does not link under cfront 2.0 (Glockenspiel 2.0c), even though no object of class X is created. However, even if things did work the way you said, it would still mean that pure virtual functions need not be defined, since it is by definition impossible to create an object of an abstract class, i.e., one that contains a pure virtual function. > 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. That's correct. > It doesn't say the function needn't be defined. Yes, it does! The second paragraph of 10.3, page 214, says, "A pure virtual function need be defined only if explicitly called with the qualified-name syntax (section 5.1)." -- William M. Miller, Glockenspiel, Ltd. wmm@world.std.com