Header Ads Widget

Destructor in C++ || constructor in c++ || C++

 

Destructor in C++

 


Destructor is a special member function that is executed automatically when an object is destroyed that has been created by the constructor.

Destructor is use to de- allocated the memory that has been allocated for the object by the constructor.

A destructor declaration should always begin with the tilde (~) symbol as shown in the following example:-


#include<iostream>
 using namespace std;
class test
{
            public:
            test()
            {
                        n=10;
                        cout<<n;
            }
            ~test()
            {
                        cout<<”object destroyed”;
            }
};

int main()
 {
            test obj;
            return 0;
}



Post a Comment

0 Comments