Sunday, 26 March 2017

c++ - Do I need to explicitly call the base virtual destructor?



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...



MyChildClass::~MyChildClass() // virtual in header
{
// Call to base destructor...
this->MyBaseClass::~MyBaseClass();


// Some destructing specific to MyChildClass
}


Am I right?


Answer



No, destructors are called automatically in the reverse order of construction. (Base classes last). Do not call base class destructors.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...