Tuesday 24 February 2015

Destructor in C++

/*
Copy constructor & Destructor
============================
*/


#include<iostream.h>
#include<conio.h>

class Date
{
private:
int dd,mm,yy;
public:
Date()
{
dd=0;
mm=0;
yy=0;
}
Date(int d,int m,int y)
{
dd=d;
mm=m;
yy=y;
}
Date(Date *p)  /* Copy Construtor */
{
dd=p->dd;
mm=p->mm;
yy=p->yy;
}
void Display()
{
cout<<"\n ToDay Date is\n";
cout<<dd<<"\\"<<mm<<"\\"<<yy;
}
~Date()
{
cout<<"\n Destructor Called";
}
};
void main()
{
clrscr();
Date d1(22,2,2005);
Date d;
d.Display();
d=d1;
d.Display();
d1.Display();
getch();
}

No comments:

Post a Comment