patterncppCritical
Do I need to explicitly call the base virtual destructor?
Viewed 0 times
destructorthevirtualbaseexplicitlycallneed
Problem
When overriding a class in C++ (with a virtual destructor) I am implementing the destructor again as virtual on the inheriting class, but do I need to call the base destructor?
If so I imagine it's something like this...
Am I right?
If so I imagine it's something like this...
MyChildClass::~MyChildClass() // virtual in header
{
// Call to base destructor...
this->MyBaseClass::~MyBaseClass();
// Some destructing specific to MyChildClass
}Am I right?
Solution
No, destructors are called automatically in the reverse order of construction. (Base classes last). Do not call base class destructors.
Context
Stack Overflow Q#677620, score: 610
Revisions (0)
No revisions yet.