Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!mucs!pjc From: pjc@cs.man.ac.uk (Peter Crowther (CAG ra)) Newsgroups: comp.lang.c++ Subject: Re: PolyMorphism Message-ID: <1167@m1.cs.man.ac.uk> Date: 11 Apr 90 08:49:50 GMT References: <1990Apr10.112351.24301@athena.mit.edu> Sender: news@cs.man.ac.uk Reply-To: pjc@cs.man.ac.uk (Peter Crowther (CAG ra)) Organization: Department of Computer Science, University of Manchester UK Lines: 30 In article <1990Apr10.112351.24301@athena.mit.edu> mleblanc@athena.mit.edu (Marc LeBlanc) writes: >>So the derived destructer won't be called if we construct the Derived >>object by Base pointer. But isn't it more natural to call both? If I >>misunderstood the C++, is there anyway you can call Derived class >>destructer? > >I think this would qualify as an "undocumented feature." If you >declare the base destructor as virtual, you get the desired effect. (I >tried it). Shouldn't this be the default? IMHO, no. Reason: I dislike languages that force me to write inefficient code (it's what comes of writing a lot of stuff on a Sun-2 (that's *2*) file server supporting about 10 clients). The default in C++ is to save the space in each object that would otherwise be allocated to the virtual function table pointer. It also maintains compatibility with C structures if the default is not to tag another pointer onto the end of each structure. That's also important to me; I have interfaces from C++ to SunView, RPC, XDR, Ingres and a bunch of C libraries. Several of these would probably screw up if virtual destructors were used. This is a weaker argument; the counterargument is 'Anyone trying to interface C++ and C should have enough nouse to change the default when they need to'. I'm just lazy. - Peter -- Peter Crowther, Dept. of Electrical Engineering, University of Manchester, Manchester M13 9PL, England. Internet: pcrowther@r1.cs.man.ac.uk Janet: pcrowther@uk.ac.man.cs.r1 ARPA: pcrowther%cs.man.ac.uk@nsfnet-relay.ac.uk OtherNets: No idea at all!