CPP

Lecture 10 : Destructors


#include<iostream>
using namespace std;

class Complex
{
	private:
		int a,b;
	public:
		Complex() //Constructor (first function of object)
		{ }
		
		~Complex() //Destructor (last function of object)
		{
			cout << "Destuctor"; 
		}
};

void fun()
{
	Complex c1; //this object will get destroyed when fun function has completed its work.
}

int main()
{
	fun();
}

Why destructor?

It should be defined to release (or access) resources allocated to an object.