A pure virtual destructor is a destructor declared with the pure-specifier (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
= 0) that renders its containing class abstract, preventing direct instantiation. Unlike standard pure virtual methods, a pure virtual destructor must be explicitly defined (implemented) in the program.
When an object of a derived class is destroyed, the C++ destruction sequence dictates that destructors are invoked in the reverse order of construction: the derived class destructor executes first, followed implicitly by the base class destructor. Because the compiler automatically injects this call to the base destructor at the end of the derived destructor’s execution, the base class must provide a valid function body. If the definition is omitted, the compiler will accept the pure declaration, but the linker will generate an unresolved external symbol error.
Crucially, unlike standard pure virtual functions, a derived class is not required to explicitly declare and define a destructor to become a concrete class. If the derived class omits an explicit destructor, the compiler-generated default destructor automatically overrides the base class’s pure virtual destructor and fulfills the requirement to instantiate the derived type.
- Out-of-Class Definition: The definition of a pure virtual destructor cannot be provided inside the class body alongside the
= 0specifier. It must be defined outside the class definition. However, the implementation can still be marked with theinlinekeyword, provided the inline definition occurs outside the class body. - Abstract Enforcement: Applying
= 0to the destructor forces the class to be abstract even if it contains no other pure virtual functions. - Vtable Mechanics and Linkage: The pure virtual destructor occupies a slot in the virtual method table (vtable). The derived class overrides this slot with its own destructor. Because the derived destructor statically calls the base destructor at the end of its execution, the base implementation must exist somewhere in the program (in any translation unit) so the linker can successfully resolve the symbol.
- Modern C++ (C++11+): The mandatory out-of-class definition can utilize the
defaultspecifier to instruct the compiler to generate a standard, empty implementation.
Master C++ with Deep Grasping Methodology!Learn More





