[C++] virtual destructor behavior
From: Spacen Jasset (spacenjasset_at_fastmail.fm)
Date: 02/29/04
- Next message: Chris \( Val \): "Re: Confused about iterator_tags and iterator_traits"
- Previous message: Francis Glassborow: "Re: When to introduce exception safety"
- Next in thread: Chris \( Val \): "Re: [C++] virtual destructor behavior"
- Reply: Chris \( Val \): "Re: [C++] virtual destructor behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 29 Feb 2004 11:31:26 -0000
I have this scenario:
class BASE
{
// virtual ~BASE() {}
};
class SUB : public BASE
{
list<char*> patterns;
~SUB()
{
cout << "~SUB()" << endl;
}
};
Then I say:
SUB *s = //something;
delete s;
It seems that the destructor for patterns in SUB doesn't get called, but
~SUB() does get called. This is not what I expected. Giving BASE a virtual
destructor fixes this. I would expect this not to work if 's' had the static
type BASE, but it does not. it's static type is SUB.
- Next message: Chris \( Val \): "Re: Confused about iterator_tags and iterator_traits"
- Previous message: Francis Glassborow: "Re: When to introduce exception safety"
- Next in thread: Chris \( Val \): "Re: [C++] virtual destructor behavior"
- Reply: Chris \( Val \): "Re: [C++] virtual destructor behavior"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|