Destructor is a member function which destructs or deletes an object.
It destructs the objects of classes.
It can be defined only once in a class.
It is invoked automatically when the object
goes out of scope.
Destructors have same name as the class name preceded by a tilde (~).
Destructors don’t take any argument and don’t return anything
Example:
#include
<iostream.h>
#include<conio.h>
class A
{
public:
A()
{
cout<<"Hello,Welcome to
LearningPoint92"<<endl;
}
~A()
{
cout<<"Destructor
Example "<<endl;
}
};
void main()
{
clrscr();
A a1;
getch();
}
Output:
Hello, Welcome to
LearningPoint92
No comments:
Post a Comment