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: <9555@alice.UUCP> Date: 3 Jul 89 22:28:55 GMT References: <1570@cadillac.CAD.MCC.COM> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 28 In article <1570@cadillac.CAD.MCC.COM>, rpj@redcloud.cad.mcc.com (Rich Johns) writes: > Assume the class Blue, which is a PrimaryColor, which is a Color. All three classes > have destructors. If I have a Blue b allocated from free store: > Blue* b = new Blue; In other words, your declarations look like this: class Color { /* stuff */ }; class PrimaryColor: public Color { /* more stuff */ }; class Blue: public PrimaryColor { /* still more stuff */ }; > Now if I: > delete b; > will the destructors for PrimaryColor and Color be called? Yes. More specifically, when you said `new Blue,' that caused the constructors for Color, PrimaryColor, and Blue to be executed in that order. When you say `delete b,' it causes the destructors for Blue, PrimaryColor, and Color to be executed in that order. -- --Andrew Koenig ark@europa.att.com