本篇博客主要是实现一个日期类,这就要求你必须对构造函数,拷贝构造函数,赋值运算符重载,输出运算符重载,友元函数等等都要熟悉
#include<iostream>
using namespace std;
class Date
{
public:
Date(int year = 2000, int month = 1, int day = 1);
Date(const Date&d);
int IsLeapYear();
Date& operator++();
Date operator++(int);
Date& operator--();
Date operator--(int);
Date operator-(int day);
Date operator+ (int day);
int operator-(const Date&d);
int operator==(const Date&d);
int operator!=(const Date&d);
int operator>(const Date&d);
int operator<(const Date&d);
friend ostream& operator<<(ostream&cout, const Date d);
Date& operator= (const Date&d);
private:
int GetMonthDays(int month)//获取每个月的天数
{
int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (IsLeapYear() && (2 == month))
{
days[month] += 1;
}
return days[month];
}
int _year;
int _mont