Destructor of a class, Pupose of desctrucor, example of destructor in OOP C++

The destructor of a class, Purpose of the destructor, an example of destructor in OOP C++.

In this tutorial, we will learn about the followings;

  1. What is destructor of a class in OOP C+?
  2. What is the purpose of destructor in OOP C+?
  3. Example of destructor in OOP C+

What is the destructor of a class?

The destructor is a member function of the class. Destructor has the same name as the name of its class. The Tild sign ∼ is used before the name of the destructor.

  • When the object of the class destroyed, destructor also destroyed automatically.
  • One class can have only one destructor. However, one class can have many constructors.
  • Destructor overloading is impossible.
  • The Destructor can’t have any arguments(parameters).
  • The destructor have no data type.

What is the purpose of the destructor of a class?

The main purpose of the destructor of a class is to free computer memory.

Program of a destructor of a class

Output

sum of 2 numbers is 6

destructor completed its work to free the memory

Video Lecture

Test Your Understandings

1.Multiple destructor for a class are possible? YES / NO

Answer - Click Here:
NO

2. Destructor for a class is represented with…………..sign?

Answer - Click Here:
∼ Tild sign

3. Destructor overloading is  very helpful to free the computer memory?

Answer - Click Here:
No, it is not possible

Topic Covered

Destructor of a class, Pupose of desctrucor, example of destructor in OOP C++.

By: Prof. Fazal Rehman Shamil    CEO @ T4Tutorials
Whatsapp: +92 302 87 000 85     Facebook: For Discussions

Leave a Reply

Your email address will not be published. Required fields are marked *