Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!netcom!sjsumcs!horstman From: horstman@sjsumcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++ Subject: Re: PolyMorphism Message-ID: <1990Apr11.053453.11504@sjsumcs.sjsu.edu> Date: 11 Apr 90 05:34:53 GMT References: Reply-To: horstman@sjsumcs.SJSU.EDU (Cay Horstmann) Distribution: comp Organization: San Jose State University Lines: 33 In article chin@sg1.chem.upenn.edu (Chin Wu) writes: > > 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: > >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; >} >... is there anyway you can call Derived class >destructer? > Yes. Declare the destructor to be virtual (in the Base.) Cay