Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: do destructors descend hierarchy? Message-ID: <9566@alice.UUCP> Date: 6 Jul 89 02:54:04 GMT References: <1570@cadillac.CAD.MCC.COM> <9555@alice.UUCP> <42280@bbn.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 21 In article <42280@bbn.COM>, lpringle@bbn.com (Lewis G. Pringle) writes: > Is there any rationale at all (beyond a slight effecicy issue in case of > classes with dtors not derived from) for not making dtors always virtual? No, but the efficiency issue is not always slight. For example, if the class has no virtual functions aside from the destructor, making the destructor virtual will cause the class to acquire a (hidden) pointer to a virtual table. If the class itself is very small, this pointer may be a significant fraction of the space occupied by an object, which in turn may make a difference if you have zillions of objects. Such matters can be important in things like string classes. Note also that you can often effectively add a virtual destructor to a class that doesn't have one by deriving a class of your own that has a virtual destructor and nothing else. -- --Andrew Koenig ark@europa.att.com