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

手机网站菜单网页怎么做安卓搭建网站

手机网站菜单网页怎么做,安卓搭建网站,电动车行业网站建设,网站正在建设中 英文赋值运算符重载 运算符重载 C 为了 增强代码的可读性 引入了运算符重载 , 运算符重载是具有特殊函数名的函数 ,也具有其返回值类型,函数名字以及参数列表,其返回值类型与参数列表与普通的函数类似。 函数名字为:关键…

赋值运算符重载

运算符重载

C++ 为了 增强代码的可读性 引入了运算符重载 运算符重载是具有特殊函数名的函数 ,也具有其返回值类型,函数名字以及参数列表,其返回值类型与参数列表与普通的函数类似。
函数名字为:关键字 operator 后面接需要重载的运算符符号
函数原型: 返回值类型  operator 操作符 ( 参数列表 )
注意:
1.不能通过连接其他符号来创建新的操作符:比如 operator@
2.重载操作符必须有一个类类型参数,就是至少有一个参数是 自定义类型。
3.用于内置类型的运算符,其含义不能改变,例如:内置的整型 + ,不能改变其含义
4.作为类成员函数重载时,其 形参看起来比操作数数目少1 ,因为成员函数的第一个参数为 隐藏的this
5.  .*    ::   sizeof    ?:    .   注意以上 5 个运算符不能重载。
6.不能改变操作符的操作数个数,一个操作符有几个操作数在重载的时候就要有几个参数
// 全局的operator==
class Date
{ 
public:Date(int year = 1900, int month = 1, int day = 1){_year = year;_month = month;_day = day;}    
//private:int _year;int _month;int _day;
};bool operator==(const Date& d1, const Date& d2)
{return d1._year == d2._year&& d1._month == d2._month&& d1._day == d2._day;
}
void Test ()
{Date d1(2018, 9, 26);Date d2(2018, 9, 27);cout<<(d1 == d2)<<endl;
}
class Date
{ 
public:Date(int year = 1900, int month = 1, int day = 1)
{_year = year;_month = month;_day = day;}bool operator==(Date* this, const Date& d2)这里需要注意的是,左操作数是this,指向调用函数的对象bool operator==(const Date& d2){return _year == d2._year;&& _month == d2._month&& _day == d2._day;}
private:int _year;int _month;int _day;
};

比较年月日时间大小

DATE

日期类运算符重载

#include<iostream>
#include<assert.h>
using namespace std;class Date
{
public:Date(int year = 1, int month = 1, int day = 1){_year = year;_month = month;_day = day;}void Print(){cout << _year << "/" << _month << "/" << _day << endl;}// d1 < d2  左操作数就是第一个参数,右操作数就是第二个参数,参数顺序不能换// 相当于下面的比较// d1.operator<(d2)     d1就是this ,d2就是d,不能换顺序bool operator<(const Date& d){if (_year < d._year){return true;}else if (_year == d._year && _month < d._month){return true;}else if (_year == d._year && _month == d._month && _day < d._day){return true;}else{return false;}}bool operator==(const Date& d){return _year == d._year&& _month == d._month&& _day == d._day;}// d1 <= d2bool operator<=(const Date& d){return *this < d || *this == d;}bool operator>(const Date& d){return !(*this <= d);}bool operator>=(const Date& d){return !(*this < d);}bool operator!=(const Date& d){return !(*this == d);}int GetMonthDay(int year, int month){int monthArray[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };if (month == 2&& ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){return 29;}return monthArray[month];}Date& operator+=(int day){_day += day;while (_day > GetMonthDay(_year, _month)){// 月进位_day -= GetMonthDay(_year, _month);++_month;// 月满了if (_month == 13){++_year;_month = 1;}}return *this;}Date operator+(int day){Date tmp(*this);tmp += day;return tmp;//tmp._day += day;//while (tmp._day > GetMonthDay(tmp._year, tmp._month))//{//	// 月进位//	tmp._day -= GetMonthDay(tmp._year, tmp._month);//	++_month;//	// 月满了//	if (tmp._month == 13)//	{//		++tmp._year;//		tmp._month = 1;//	}//}//return tmp;}private:// 内置类型int _year;int _month;int _day;
};int main()
{Date d1(2023, 7, 21);Date d2(2022, 8, 21);//这里只有两个操作数所以只能写两个参数cout << (d1 < d2) << endl;   // cout << (d1.operator<(d2)) << endl;cout << (d1 == d2) << endl;/*Date ret = d1 += 50;ret.Print();d1.Print()*/Date ret = d1 + 50;ret.Print();d1.Print();return 0;
}

http://www.yayakq.cn/news/460329/

相关文章:

  • 如何做网站推广获客怎么做产品的网站
  • 佛山设计网站设计价格网站怎么做返回主页按钮
  • 网站搜不出来怎么办2022年最火的电商平台
  • 贵阳网站建设方案咨询工地木模板多少钱一张
  • 网站推广上首页天津网站快速排名提升
  • 关闭网站跳转代码3万元简装修大全
  • 怎样查看别人的网站是怎么建设网站建设方案对比报告
  • asp.net的网站开发wordpress插件官网
  • 怎样做关键词网站金隅嘉华大厦网站建设公司
  • 安阳市建设工程招标投标协会网站新手建网站
  • 赣州网站建设优化服务海口网站排名推广
  • 牛搬家网企业网站排名谁家的网站做的比较好
  • dw做的网站怎么全屏163企业邮箱登陆口
  • 自己建网站需要服务器么北京建设银行分行招聘网站
  • 网站后台修改内容看不见了wordpress添加小说
  • 做微信小程序的网站旅游最好的网站建设
  • 四川网站建设制作软件界面设计欣赏
  • 微信订阅号网站开发做网站 就
  • 遵义做网站 0852t什么网站可以做章
  • 网站开发服务外包合同宿迁房产网丫丫
  • 商务网站开发的的基本流程湘潭做网站 磐石网络
  • 企业高端网站网站支付宝接口付费
  • 国内互动网站建设鄞州区建网站外包
  • 移动端公众号网站开发wordpress创建企业邮箱
  • 给一个网站做需求分析wordpress开启redis
  • app开发与网站开发有何不同信用中国官网企业查询
  • 营销网站的优势是什么意思深圳燃气公司网上营业厅
  • 外包建设网站平面设计专业课程有哪些
  • wordpress视频无法播放视频播放seo分析报告
  • 免费网站设计软件国外做问卷调查的网站