#pragmaonce#include<iostream>#include<assert.h>#include<stdbool.h>using std::cout;using std::cin;using std::endl;classDate{public:Date(int year =0,int month =1,int day =1);voidPrint();
Date&operator+=(int days);
Date operator+(int days);
Date&operator-=(int days);
Date operator-(int days);booloperator>(const Date& oneday);booloperator>=(const Date& oneday);booloperator<(const Date& oneday);booloperator<=(const Date& oneday);booloperator==(const Date& oneday);booloperator!=(const Date& oneday);//两个日期相减intoperator-(const Date& oneday);//前置++ ++d -> d.operator(&d);
Date&operator++();//后置++ d++ ->d.operator(&d,int)// int参数不许要给实参,只是为了和前置++构成重载
Date operator++(int);//前置--
Date&operator--();//后置--
Date operator--(int);private:int _year;int _month;int _day;};
源文件(Date.cpp)
#include"Date.h"//判断闰年boolis_leapyear(int year){if((year %4==0&& year %100!=0)||(year %400==0)){returntrue;}returnfalse;}//准备好每个月的天数inlineintGetMonthDay(int year,int month){staticint dayArray[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int day = dayArray[month];if(month==2&&(year %4==0&& year %100!=0)||(year %400==0)){
day =29;}return day;}