Date(日期类):各种接口的实现

本文详细探讨了Date类中各种接口的实现,包括关键注意事项,如参数传递方式、赋值操作符的调用以及this指针的使用。提醒读者在实现过程中需关注指针与引用的差别,正确调用赋值操作符,并理解this关键字的作用。
摘要由CSDN通过智能技术生成

问题

class Date 
{
   
public:    
	Date(int year = 1900, int month = 1, int day = 1);//构造函数
	Date(const Date& d);//拷贝函数
	Date& operator=(const Date& d);//赋值
	Date operator+(int days);// 从当前日期 + N 天

	Date operator-(int days);// 从当前日期 - N天
	int operator-(const Date& d);//两个日期相差的天数
	Date& operator++();//前置++
	Date operator++(int);//后置++
	Date& operator--();//前置--
	Date operator--(int);//后置--
	
	//判断两个日期之间的大小
	bool operator>(const Date& d)const;
	bool operator>=(const Date& d)const;
	bool operator<(const Date& d)const;
	bool operator<=(const Date& d)const;
	bool operator==(const Date& d)const; 
	bool operator!=(const Date& d)const;
	
private:    
	int _year;
	int _month;
	int _day;
};

下面实现函数:

#include<iostream>
#include<stdlib.h>

using namespace std;


class Date
{
   
public:


	int Monthday(int year, int month)//计算这个月有多少天
	{
   
		int a[13] = {
    0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值