#include <iostream.h>
#include <stdlib.h>
class Date
{
public:
Date();
Date(int y,int m,int d);
void setdate(int y,int m,int d);
void showdate();
private:
int year,month,day;
};
void Date::setdate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
cout<<"使用有参构造成功!\n";
}
Date::Date()
{
year=1990;
month=11;
day=19;
cout<<"使用无参构造成功!\n";
}
inline void Date::showdate()
{
cout<<year<<"."<<month<<"."<<day<<endl;
}
void main()
{
Date *p,*date2;
//指针
Date date;
//无参
Date date1(1989,11,19);
//有参
cout<<"人物1:";
date1.showdate();
cout<<"人物2:";
date.showdate();
p=&date2;
p->setdate(1991,11,19);
p->showdate();
}