CPP Language / Destructors

It is class member function used to delete an object and they don’t take any argument and don’t return anything. Destructors have same name as their class and their name is preceded by a tilde(~).

Program Output

#include
using namespace std;
class a
{
private: int num1, num2;
public: a(int n1, int n2)
{
cout<<"Inside Constructor"< num1 = n1; num2 = n2;
}

void am()
{
cout<<"num1 = "<< num1 < }

~a() { cout<<"Inside Destructor"; }
};

int main()
{
a aobj1(10, 20);
aobj1.am();
return 0;
}

Inside Constructor
num1 = 10
Inside Destructor


Home     Back