Tuesday, 24 February 2015

Default Argument Constructor in C++

/*
Default Argument Constructor & Destructor
==========================================
*/

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

class Date
{
private:
int dd,mm,yy;
public:
Date(int d=10,int m=2,int y=2005) /* Default Argument Constructor */
{
dd=d;
mm=m;
yy=y;
}
void Display()
{
cout<<"\n ToDay Date is\n";
cout<<dd<<"\\"<<mm<<"\\"<<yy;
}
~Date()
{
cout<<"\n Destructor Called";
}
};
void main()
{
clrscr();
Date d;    /* Default Constructor is Called */
d.Display();
Date d1(22,5);  /* Constructor is Called */
d1.Display();
Date d2(22,4,2006);
d2.Display();
getch();
}

No comments:

Post a Comment