inline bool operator >= (const Date& d);
// <运算符重载
bool operator < (const Date& d);
// <=运算符重载
bool operator <= (const Date& d);
// !=运算符重载
bool operator != (const Date& d);
// 日期-日期 返回天数
int operator-(const Date& d);
private:
int _year;
int _month;
int _day;
};
日期类的拷贝构造,析构,复制重载用默认生成的就行。
---
## 三、接口实现
### 3.1 构造函数及检查日期合法
Date::Date(int year, int month, int day)
{
//判断日期是否合法
if (year >= 0
&& month >= 1 && month <= 12
&& day >= 0 && day <= GetMonthDay(year, month))
{
_year = year;
_month = month;
_day = day;
}
else
{
cout << “非法日期” << endl;
}
}
注意缺省参数在声明和定义只能出现一处,GetMonthDay函数在后面讲解。
---
### 3