Search code examples
c++abstract-classdestructorpure-virtual

Should an abstract class' destructor be pure virtual?


I think virtual alone is generally sufficient.

Is there another reason to make it pure virtual than to force derived classes to implement their own destructor? I mean if you allocate something in your class' constructor you should impement your own destructor - if your class is derived or not.

Doesn't count as answer as I already know: If you want your class abstract and it has no pure virtual functions - leave it to the destructor.

Some more uses?


Solution

  • If you want your class abstract and it has no pure virtual functions - leave it to the destructor.

    Actually, I don't think there's more. All the pure virtual destructor does, is make the whole class abstract. You have to provide the implementation for the pure virtual destructor as well as for a non-pure virtual destructor, the destructors of the derived classes are virtual with virtual destructor alone, etc.

    Basically, if a class has already some pure virtual functions, its behaviour would be equivalent with virtual and pure-virtual destructor.