Pure Virtual Destructors

Pure Virtual Destructors

I heard someone saying that C++ standardization does not allow pure virtual destructors not to have a definition.

As far as I know, this is not true. Could you please confirm? I cannot find the relevant information.

It is true: a pure virtual destructor must be defined. The reason is that a derived object’s destructor recursively calls its base class’s destructor. When the base’s destructor is only declared but not implemented (as is the case of a nonimplemented pure virtual destructor), the compiler issues an error message, and rightfully so. The implementation of a pure virtual destructor is located outside the class declaration, and it must be empty:

 class A{public: virtual ~A()=0; //declaration};virtual A::~A(){} //implementation


Share the Post: