Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!kth!draken!tut!tukki!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: do destructors descend hierarchy? Message-ID: <982@tukki.jyu.fi> Date: 5 Jul 89 05:41:35 GMT References: <1570@cadillac.CAD.MCC.COM> <9555@alice.UUCP> Reply-To: markku@jytko.jyu.fi (Markku Sakkinen) SAKKINEN@FINJYU.bitnet (alternative) Organization: University of Jyvaskyla, Finland Lines: 50 In article <9555@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: -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 Please, remember that you are using C++ release 2.0 yourself but we others outside Bell Labs have not got it (at least yet)! The sad fact about earlier AT&T releases is that if there is an assignment to the variable this in a constructor (destructor) of a derived class, the constructor (destructor) of its base class will never be called. I don't know about those C++ compilers (Oregon Software, Zortech, GNU, others?) that are not based on AT&T's product. As shown in my paper at ECOOP'88, the whole idea of assigning to "this" in constructors and destructors causes a mess. Fortunately it seems to get replaced by an orderly possibility to overload the operators new and delete in release 2.0. Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland