Have I Got This Inheritance Code Right?
I've got this code segment which I'm unsure about. Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
struct BASE
{
BASE( void )
{
this->Member = ( new int( 10 ) );
}
virtual ~BASE( void )
{
delete this->Member;
}
int *Member;
};
struct PARENT : public BASE
{
PARENT( void )
{
this->Bases = ( new BASE[ 3 ] );
}
~PARENT( void )
{
delete [ ] Bases;
}
BASE *Bases;
};
|
Will the destructor of
BASE be called in this code segment? I understand inheritance, I just don't understand how the destructors are affected.
Wazzak
Last edited on
Yeah, destructors of derived classes always call the destructors of all their base classes.
Topic archived. No new replies allowed.