Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!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: <1991Jun4.134034.21404@world.std.com> Date: 4 Jun 91 13:40:34 GMT References: <183@swampthing.sbi.com> <1991Jun1.192610.18321@borland.com> <185@swampthing.sbi.com> Organization: Glockenspiel, Ltd. Lines: 24 wfl@swampthing.sbi.com (W. Linke CPE) writes: > A pure virtual member function *MAY* be defined for the abstract class in which > it is declared, but it *MUST* be overridden in some class derived from the > abstract class in order to create class objects, > > but a pure virtual destructor *MUST* be defined for the abstract class in which > it is declared, while it *MAY* be "overridden" in classes derived from the > abstract class. > > "Pure virtual" in the above really means two different (overlapping) things. Actually, that's not quite correct. "Pure virtual" means the same in both cases; it's just that the special characteristics of destructors cause the compiler to do certain things for you that have to be done manually for ordinary member functions. Specifically, a pure virtual member function "*MUST* be defined" if it is ever invoked; constructors are guaranteed to be 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. -- William M.