Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.c++ Subject: Re: Base class vs. derived class and delete Message-ID: <1991Mar15.132452.26522@clear.com> Date: 15 Mar 91 13:24:52 GMT References: <1991Mar12.202624.19872@bwdls61.bnr.ca> Organization: Clear Communications, Inc. Lines: 20 In article <1991Mar12.202624.19872@bwdls61.bnr.ca> gwaters@bwdls35.bnr.ca (Glenn Waters) writes: >The following program does not do what I would hope (expect). The third line of >main does a "delete bp". This seems to only delete String _b in the base class >and *not* String _d in the derived class. Is delete not a "virtual" delete >in that it will delete _d in the derived class? I realize I could have written >"delete dp", but that is not possible when there are multiple classes derived >from the base class. [... example deleted ....] This case is explained in ARM 12.4 in the discussion of virtual destructors. In answer to your question about "delete". It is not "delete" which is virtual... If you want virtual "deletion" then you must declare virtual destructors. -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |