C++ Logo.wine
C++

xplain the Destructor in detail with the help of examples, in context of C++ programming.

Destructor :-

it is also special member of class having same name but is defined with (tilde) ~ sign.

  • It can be parameterised.
  • It can’t be overloaded.
  • It does not return a value even void.
  • It is called automatically when delete an object.
Example:-
#include<iostream.h>
#include<conio.h>
classpix
{
public:
pix()
{
cout<<“\n This is constructor”;
}
~pix()
{
cout<<“\n This is destructor”;
}
};
void main()
{
clrscr();
pix *op=new pix();
delete op;
getch();
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.