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

See also  Why ChatGPT Is So Important Today

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist