Destructor in C++ Language

Destructor in C++ Language


What is Destructor ?


destructor in c++,destructor in php,destructor in java


Example :-


destructor,destructor in c++,destructor in php
Destructor

Here we seen in above example that destructor is almost similar to Constructor. And  if we don't write our own destructor in class, compiler creates a default destructor for us but this type of destructor is called empty destructor.

How to call Destructor ?

It is invoked implicitly when object is going to destroy. Destructor is the last function in the life of the object(which called and run).


Example:-



destructor,destructor in c++,destructor in php
Destructor


As we have seen in the quotation given above, fun() Function will be called before getch() function
and As soon as the work of fun function is over, the object will also destroy, To see if a destructor has been run or not, we have written a statement in distructor and if this statement is run then our destructor will run too.

OUTPUT 



Here we have seen in the output given above that destructor will display on screen that's mean destructor will run before the object destroy."The purpose of the destructor is to free the resources that the object may have acquired during its lifetime".


If this article is helpful to you then please like and share. thank you..

Comments

Popular posts from this blog

Notepad, Wordpad and Paint

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN