Re: Polymorphism
From: Rich (Someone_at_somewhere.com)
Date: 12/11/04
- Previous message: Mike Wahler: "Re: Elegant way to do this?"
- In reply to: Chris \( Val \): "Re: Polymorphism"
- Next in thread: B. v Ingen Schenau: "Re: Polymorphism"
- Reply: B. v Ingen Schenau: "Re: Polymorphism"
- Reply: Anthony Borla: "Re: Polymorphism"
- Reply: JoeC: "Re: Polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 11 Dec 2004 00:59:10 +0000 (UTC)
Hello,
I am intrigued by this post and the program :)
I have not really got as far as polymorphism yet, but a google says
something about setting the base class destructor as virtual as well and
then also making derived classes destructors virtual
something to do with making the whole chain of destructors being called.
So I am thinking that if the Base class destructor is not made virtual
then when delete is called it won't call the derived classes destructor
but it's own one instead?
Am I also right in saying that a destructor is only needed to be made
virtual if it has virtual functions in it otherwise there is no point
making the destructor virtual?
So the code might look like this?
class Base
{
public:
virtual void Print() = 0;
virtual ~Base () {};
};
class X : public Base { public: virtual void Print()
{ std::cout << "X::DoIt\n"; } virtual ~X () {} };
class Y : public Base { public: virtual void Print()
{ std::cout << "Y::DoIt\n"; } virtual ~Y () {} };
class Z : public Base { public: virtual void Print()
{ std::cout << "Z::DoIt\n"; } virtual ~Z () {} };
anywhere close?
- Previous message: Mike Wahler: "Re: Elegant way to do this?"
- In reply to: Chris \( Val \): "Re: Polymorphism"
- Next in thread: B. v Ingen Schenau: "Re: Polymorphism"
- Reply: B. v Ingen Schenau: "Re: Polymorphism"
- Reply: Anthony Borla: "Re: Polymorphism"
- Reply: JoeC: "Re: Polymorphism"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|