say I have the following:
class Foo {
public:
void destroy();
~Foo()
{
destroy();
}
};
class Bar : public Foo {
public:
~Bar() {}
};
If I have a Bar object, will Foo's destructor be called when the Bar objected is deleted?
Thanks
Yes.
But the above code is dangerous; if you don't declare ~Foo() as virtual, then ~Bar() won't be called if you invoke delete on a Bar object via a Foo *.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With