
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Pure virtual destructor in C++
The pure virtual destructor is possible in C++. If a class contains pure virtual destructor it is must to provide a function body for the pure virtual destructor.
Example Code
#include <iostream> using namespace std; class B { public: virtual ~B()=0; // Pure virtual destructor }; B::~B() { std::cout << "Pure virtual destructor is called"; } class D : public B { public: ~D() { cout << "~D() is executed"<<endl; } }; int main() { B *bptr=new D(); delete bptr; return 0; }
Output
~D() is executed Pure virtual destructor is called
- Related Articles
- Why do we need a pure virtual destructor in C++?
- Virtual Destructor in C++
- Difference Between Virtual and Pure Virtual Function
- Difference between a virtual function and a pure virtual function in C++
- Pure Virtual Functions and Abstract Classes in C++
- Why is a C++ pure virtual function initialized by 0?
- Private Destructor in C++
- Difference Between Constructor and Destructor
- Order of Constructor/ Destructor Call in C++
- How does the destructor method __del__() work in Python?
- attribute((constructor)) and attribute((destructor)) syntaxes in C in tutorials point ?
- Pure Function in C++
- Pure Component in React.js
- Pure ALOHA
- What are pure substances ? Give two examples of pure substances.

Advertisements