Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!netnews.upenn.edu!chin From: chin@sg1.chem.upenn.edu (Chin Wu) Newsgroups: comp.lang.c++ Subject: PolyMorphism Message-ID: Date: 9 Apr 90 21:45:55 GMT Sender: news@netnews.upenn.edu Distribution: comp Organization: University of Pennsylvania, Philadelphia, PA Lines: 45 If we use a Base pointer to construct a Derived object, will the Derived destructer be used when been deleted? I have used the following code to explore: -------------------------- // test derived constructer and destructer #include class Base { public: Base() { cout << "This is base constructer\n";}; ~Base() { cout << "This is base destructer\n";}; }; class Derived : public Base { public: Derived() { cout << "This is derived constructer\n";}; ~Derived() { cout << "This is derived destructer\n";}; }; main() { Base* test; test = new Derived; delete test; } ---------------------------- And the output as follow: This is base constructer This is derived constructer This is base destructer 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? ps: I am using GNU G++, maybe AT&T behave differently. -- chin@sg1.chem.upenn.edu