Absatrct class destructors : why ?

If I understand well an abstract class needs to have an explicitly defined destructor, correct?

At the minimum, this will do:

~myClass(){}

But not this:

~myClass()=0;

And all derived classes must also have an explicitly defined destructor, correct?


What I don’t understand is why. Why didn’t the designers of C++ allow of implicit destructors?
Last edited on
If I understand well an abstract class needs to have an explicitly defined destructor, correct?

Well, you don't have to, but normally you want the destructor to be virtual if you intend to inherit from the class, otherwise deleting a derived object through a base class pointer will not work correctly, so that is why you do it.

 
virtual ~MyClass() = default;


And all derived classes must also have an explicitly defined destructor, correct?

No, implicitly-declared destructors are often all you need.
Last edited on
Topic archived. No new replies allowed.