friend Date operator ++(Date d,int n) //重载运算符+
friend Date operator +(Date d,int n) //重载运算符+
friend Date operator +(Date d,int n) //重载运算符+
friend Date operator +(Date &d,int n) //重载运算符+
#include <iostream.h>
class Date
{ private :
int year, month, day;
public :
Date(int y=2000, int m=1, int d=1)
{ year=y; month=m; day=d; }
void print()
{ cout<<year<<"/"<<month<<"/"<<day<<endl; }
friend Date operator +(Date &d,int n) //重载运算符+
{ Date dd;
dd.year=d.year;
dd.month=d.month;
dd.day=d.day+n ;
return dd; }
};
main()
{ Date d1(2004,10,8), d2;
d2=d1+5; //使用重载运算符+
d1.print(); //显示:2004/10/8
d2.print(); //显示:2004/10/13
}