C++ Program using destructor


In this program, You will learn how to implement destructor in C++.


Destructor in C++

~Test( ) {
    //statement
}

Example: How to implement destructor in C++.

#include<iostream>
using namespace std;

class Test {
public:

    Test() {
       cout << "Constructor is called here";
    }

   ~Test() {
       cout << "\nDestructor is called here";
   }
};

int main() {

   Test tt;

   return 0;
}

Output:

Constructor is called here
Destructor is called here