Destructor in C++ Language
Destructor in C++ Language
What is Destructor ?
Example :-
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 |
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
If this article is helpful to you then please like and share. thank you..
Comments
Post a Comment