当前位置: 首页 > news >正文

怎样做o2o网站百度云盘网页版

怎样做o2o网站,百度云盘网页版,智慧团建网站登录密码是啥,最近的重大国际新闻在上篇博客中,我们已经对于日期类有了较为全面的实现,但是,还有一个问题,比如说,我给一个const修饰的日期类的对象 这个对象是不能调用我们上篇博客写的函数的,因为&d1是const Date*类型的&#xff…

在上篇博客中,我们已经对于日期类有了较为全面的实现,但是,还有一个问题,比如说,我给一个const修饰的日期类的对象
在这里插入图片描述
在这里插入图片描述

这个对象是不能调用我们上篇博客写的函数的,因为&d1是const Date*类型的,而this指针是Date*类型,&d1传给this是一种权限的放大,这是不行的,所以,我们要改造一下相关函数,就是声明和定义都要加上const,那么具体形式如下
在这里插入图片描述
在这里插入图片描述
不只是这一个函数,像比较大小,加减天数等,凡是不改变this指针指向的内容的值的,都要加const,那么<<这个符号加const吗?不用,因为这不是成员函数,没有this指针
关于日期类的所有代码我会放在这篇文章的最后,下面我们来说最后两个类的默认成员函数,就是取地址操作符重载和const修饰的取地址操作符重载
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
这个默认成员函数确实没什么实际的作用,就算我不写这个函数,直接取地址也不会有任何问题,唯一的作用就是你可以选择不返回this,而返回空或一个假地址
Date.h文件

#include<iostream>
#include<assert.h>
using namespace std;
class Date {
public:Date(int year = 1, int month = 1, int day = 1);Date* operator&();const Date* operator&()const;void Print()const;int GetMonthDay(int year, int month);bool operator==(const Date& n);bool operator!=(const Date& n);bool operator<(const Date& n);bool operator<=(const Date& n);bool operator>(const Date& n);bool operator>=(const Date& n);Date& operator+=(int day);Date operator+(int day);Date& operator-=(int day);Date operator-(int day);Date& operator++();//前置++Date operator++(int);//后置++Date& operator--();Date operator--(int);int operator-(const Date& d);friend ostream& operator<<(ostream& out, const Date& d);friend istream& operator>>(istream& in,  Date& d);private:int _year;int _month;int _day;
};ostream& operator<<(ostream& out, const Date& d);
istream& operator>>(istream& in,  Date& d);

Date.cpp文件

#include"Date.h"
Date::Date(int year, int month , int day ) {_year = year;_month = month;_day = day;if (_year < 1 || _month < 1 || _month>12 || _day<1 || _day>GetMonthDay(_year, _month)) {cout << _year << "年" << _month << "月" << _day << "日";cout << "日期非法" << endl;}
}
Date* Date:: operator&() {return this;
}const Date* Date::operator&()const {return this;
}void Date::Print() const{cout << _year << "年" << _month << "月" << _day << "日" << endl;
}int Date :: GetMonthDay(int year, int month) {assert(year >= 1 && month >= 1 && month <= 12);int monthArray[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };if ((month == 2) && (((year % 400) == 0) || ((year % 4) == 0 && (year % 100) != 0))) {return 29;}return monthArray[month];
}bool Date:: operator==(const Date& n) {return _year == n._year && _month == n._month && _day == n._day;
}bool Date::operator!=(const Date& n) {return !(*this == n);
}bool Date:: operator<(const Date& n) {if (_year < n._year) {return true;}if (_year == n._year && _month < n._month) {return true;}if (_year == n._year && _month == n._month && _day < n._day) {return true;}return false;
}bool Date::operator<=(const Date& n) {return ((*this < n) || (*this == n));
}bool Date::operator>(const Date& n) {return !(*this <= n);
}bool Date:: operator>=(const Date& n) {//return *this > n || *this == n;return !(*this < n);
}Date& Date:: operator+=(int day) {if (day < 0) {return *this -= (-day);}if (day < 0) {return *this -= (-day);}_day += day;while (_day > GetMonthDay(_year, _month)) {_day -= GetMonthDay(_year, _month);++_month;if (_month == 13) {++_year;_month = 1;}}return *this;
}Date Date:: operator+(int day) {Date tmp(*this);tmp += day;return tmp;
}Date& Date:: operator-=(int day) {if (day < 0) {return *this -= (-day);}if (day < 0) {return *this += (-day);}_day -= day;while (_day <= 0) {--_month;if (_month == 0) {--_year;_month = 12;}_day += GetMonthDay(_year, _month);}return *this;
}Date Date:: operator-(int day) {Date tmp(*this);tmp -= day;return tmp;
}Date& Date::operator++() {*this += 1;return *this;
}Date Date:: operator++(int) {Date tmp(*this);*this += 1;return tmp;
}Date& Date::operator--() {*this -= 1;return *this;
}Date Date:: operator--(int) {Date tmp(*this);*this -= 1;return tmp;
}//int Date::operator-(const Date& d) {
//	int flag = -1;
//	Date min = *this;
//	Date max = d;
//	if (*this > d) {
//		min = d;
//		max = *this;
//		flag = 1;
//	}
//	int n = 0;
//	while (min < max) {
//		++min;
//		++n;
//	}
//	return n*flag;
//}
int Date::operator-(const Date& d) {int flag = 1;Date max = *this;Date min = d;if (*this < d) {max = d;min = *this;flag = -1;}int n = 0;int y = min._year;while (y != max._year) {if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {n += 366;}else {n += 365;}y++;}int m1 = 1;int m2 = 1;while (m1 < max._month) {n += GetMonthDay(max._year, m1);m1++;}while (m2 < min._month) {n -= GetMonthDay(min._year, m2);m2++;}n = n + max._day - min._day;return n;
}
ostream& operator<<(ostream& out, const Date& d) {out << d._year << "-" << d._month << "-" << d._day << endl;return out;
}istream& operator>>(istream& in,  Date& d) {in >> d._year>>d._month >> d._day;return in;
}
http://www.dinnco.com/news/40856.html

相关文章:

  • 阿里云网站备案时间怎么制作小程序
  • 马云不懂技术如何做网站win10优化软件
  • 网站3级目录可以做导航分类么凡科网怎么建网站
  • 日本 wordpressseo分析报告怎么写
  • 上海地区做旧物回收的网站辽源seo
  • 河南洛阳网站建设搜索引擎数据库
  • wordpress彩色内链广州seo软件
  • WordPress多站点恢复手机如何做网站
  • 在线相册jsp网站开发与设计都有什么推广平台
  • 济南网站建设求职淘宝seo是什么
  • 余姚网站建设哪家好营销型网站建设优化建站
  • 中国建设银行黑龙江支行官方网站今日中央新闻
  • google英文网站现在学seo课程多少钱
  • 网站建设方案规划书2022年每日新闻摘抄10一30字
  • 网站建设注意什么seo云优化公司
  • 哪里有手机网站建设公司磁力王
  • 客户网站 备案电子商务营销策划方案
  • 企业网站的功能模块免费有效的推广网站
  • 个人主页网站模板50个市场营销经典案例
  • 临沂企业网站建设系统优化
  • 配置 tomcat 做网站国内网络推广渠道
  • 网站站点层叠样式怎么做百度推荐现在为什么不能用了
  • 阿里邮箱 wordpress搜索引擎优化的核心及内容
  • 苏州网站建设浅议网络营销论文
  • wordpress网站被攻击整站seo免费咨询
  • 网站搭建怎么做西安网站设计
  • 宜宾网站建设公司免费s站推广网站
  • 电脑网站和手机网站怎么做相同路径百度竞价课程
  • 做网站多少钱赚钱吗网络推广员工作内容
  • 欧美色影网站一键免费创建论坛网站