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

贵州网站建设设计公司哪家好网络优化工程师简历

贵州网站建设设计公司哪家好,网络优化工程师简历,品牌网站设计企业服务,商城小程序开发费用运算符重载 • 当运算符被⽤于类类型的对象时,C语⾔允许我们通过运算符重载的形式指定新的含义。C规定类类型对象使⽤运算符时,必须转换成调⽤对应运算符重载,若没有对应的运算符重载,则会编译报错。 • 运算符重载是具有特名字的…

运算符重载

• 当运算符被⽤于类类型的对象时,C++语⾔允许我们通过运算符重载的形式指定新的含义。C++规定类类型对象使⽤运算符时,必须转换成调⽤对应运算符重载,若没有对应的运算符重载,则会编译报错。
• 运算符重载是具有特名字的函数,他的名字是由operator和后⾯要定义的运算符共同构成。和其他函数⼀样,它也具有其返回类型和参数列表以及函数体。
• 重载运算符函数的参数个数和该运算符作⽤的运算对象数量⼀样多。⼀元运算符有⼀个参数,⼆元
运算符有两个参数,⼆元运算符的左侧运算对象传给第⼀个参数,右侧运算对象传给第⼆个参数。
• 如果⼀个重载运算符函数是成员函数,则它的第⼀个运算对象默认传给隐式的this指针,因此运算符重载作为成员函数时,参数⽐运算对象少⼀个。
• 运算符重载以后,其优先级和结合性与对应的内置类型运算符保持⼀致。
• 不能通过连接语法中没有的符号来创建新的操作符:⽐如operator@。
• .* :: sizeof ?: . 注意以上5个运算符不能重载。(选择题⾥⾯常考,⼤家要记⼀下)
• 重载操作符⾄少有⼀个类类型参数,不能通过运算符重载改变内置类型对象的含义,如: int
operator+(int x, int y)
• ⼀个类需要重载哪些运算符,是看哪些运算符重载后有意义,⽐如Date类重载operator-就有意
义,但是重载operator+就没有意义。

• 重载++运算符时,有前置++和后置++,运算符重载函数名都是operator++,⽆法很好的区分。
C++规定,后置++重载时,增加⼀个int形参,跟前置++构成函数重载,⽅便区分。
• 重载<<和>>时,需要重载为全局函数,因为重载为成员函数,this指针默认抢占了第⼀个形参位
置,第⼀个形参位置是左侧运算对象,调⽤时就变成了对象<<cout,不符合使⽤习惯和可读性。
重载为全局函数把ostream/istream放到第⼀个形参位置就可以了,第⼆个形参位置当类类型对
象。

取地址运算符重载

• 将const修饰的成员函数称之为const成员函数,const修饰成员函数放到成员函数参数列表的后⾯。
• const实际修饰该成员函数隐含的this指针,表明在该成员函数中不能对类的任何成员进⾏修改。
const修饰Date类的Print成员函数,Print隐含的this指针由 Date* const this 变为 const Date* const this
取地址运算符重载分为普通取地址运算符重载和const取地址运算符重载,⼀般这两个函数编译器⾃动⽣成的就可以够我们⽤了,不需要去显⽰实现。除⾮⼀些很特殊的场景,⽐如我们不想让别⼈取到当前类对象的地址,就可以⾃⼰实现⼀份,胡乱返回⼀个地址

日历代码

头文件
#pragma once
#include<assert.h>
#include<iostream>
using namespace std;
class Date
{friend ostream& operator<<(ostream& out, const Date& p);friend istream& operator>>(istream& in,Date& p);
public:Date(int year, int month, int day);void Print(void);bool CheckDate(){if (_month < 1 || _month>12 || _day<1 || _day > GetMonthDay(_year, _month)){return false;}else{return true;}}int GetMonthDay(int year, int month){assert(month > 0 && month < 13);static int monthDayArray[13] = { -1,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;}else{return monthDayArray[month];}}bool operator>(const Date& d);bool operator>=(const Date& d);bool operator<(const Date& d);bool operator<=(const Date& d);bool operator==(const Date& d);bool operator!=(const Date& d);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);//void operator<<(ostream& out);int operator-(const Date& d);private:int _year;int _month;int _day;
};ostream& operator<<(ostream& out,const Date& p);
istream& operator>>(istream& in,Date& p);
功能代码
#define _CRT_SECURE_NO_WARNINGS
#include "Date.h"Date::Date(int year = 2000, int month = 1, int day = 1)
{_year = year;_month = month;_day = day;if (!CheckDate()){cout << "error" << endl;cout << *this;}
}void Date::Print()
{cout << _year << "-" << _month << "-" << _day << endl;
}bool Date::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;}return false;
}bool Date::operator<(const Date& d)
{return !(*this >= d);
}bool Date::operator<=(const Date& d)
{return !(*this > d);
}bool Date::operator>=(const Date& d)
{return *this > d || *this == d;
}bool Date::operator!=(const Date& d)
{return !(*this == d);
}bool Date::operator==(const Date& d)
{return _year == d._year && _month == d._month && _day == d._day;
}Date Date::operator+(int day)
{Date tmp = *this;tmp += day;return tmp;
}
Date& 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& Date::operator-=(int day)
{_day -= day;while (_day <= 0){--_month;if (_month == 0){_month = 12;--_year;}_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)
{Date max = *this;Date min = d;int flag = 1;if (*this < d){max = d;min = *this;flag = -1;}int n = 0;while (min != max){min++;n++;}return n * flag;
}istream& operator>>(istream& in,Date& p)
{while(1){cout << "year month day";in >> p._year >> p._month >> p._day;if (p.CheckDate()){break;}else{cout << "error" << endl;}}return in;
}
ostream& operator<<(ostream& out,const Date& p)
{out << p._year << "年" <<p._month << "月" << p._day << endl;return out;
}

 


 


文章转载自:
http://mock.zydr.cn
http://aeronautic.zydr.cn
http://tabinet.zydr.cn
http://zack.zydr.cn
http://plagioclastic.zydr.cn
http://depurge.zydr.cn
http://eryngo.zydr.cn
http://fosterage.zydr.cn
http://chucklehead.zydr.cn
http://dubitatively.zydr.cn
http://robotization.zydr.cn
http://nebelwerfer.zydr.cn
http://unprevailing.zydr.cn
http://sweat.zydr.cn
http://peasecod.zydr.cn
http://halfheartedly.zydr.cn
http://zen.zydr.cn
http://ivied.zydr.cn
http://tanyard.zydr.cn
http://cetacean.zydr.cn
http://turk.zydr.cn
http://heterocyclic.zydr.cn
http://isd.zydr.cn
http://distemper.zydr.cn
http://weedkilling.zydr.cn
http://fuck.zydr.cn
http://duchenne.zydr.cn
http://geranial.zydr.cn
http://hypognathous.zydr.cn
http://praecipitatio.zydr.cn
http://psychologically.zydr.cn
http://fracturation.zydr.cn
http://pronounced.zydr.cn
http://incremental.zydr.cn
http://peritonitis.zydr.cn
http://does.zydr.cn
http://poleaxe.zydr.cn
http://segmentable.zydr.cn
http://verbal.zydr.cn
http://morality.zydr.cn
http://technicalize.zydr.cn
http://underrun.zydr.cn
http://leaper.zydr.cn
http://takaoka.zydr.cn
http://underivative.zydr.cn
http://megakaryocyte.zydr.cn
http://calligraphist.zydr.cn
http://tithonia.zydr.cn
http://pinta.zydr.cn
http://distillery.zydr.cn
http://lividity.zydr.cn
http://tinman.zydr.cn
http://disintegrative.zydr.cn
http://boil.zydr.cn
http://christianity.zydr.cn
http://dilutedness.zydr.cn
http://heteromorphism.zydr.cn
http://superimpose.zydr.cn
http://choanocyte.zydr.cn
http://faddish.zydr.cn
http://decalog.zydr.cn
http://axon.zydr.cn
http://someday.zydr.cn
http://damnedest.zydr.cn
http://rucksack.zydr.cn
http://backslapper.zydr.cn
http://graunch.zydr.cn
http://ireland.zydr.cn
http://hotchpot.zydr.cn
http://theatricals.zydr.cn
http://lateralization.zydr.cn
http://thrum.zydr.cn
http://aitchbone.zydr.cn
http://kyloe.zydr.cn
http://melon.zydr.cn
http://plumbate.zydr.cn
http://eacm.zydr.cn
http://checkerberry.zydr.cn
http://conchiolin.zydr.cn
http://schizo.zydr.cn
http://seicento.zydr.cn
http://stake.zydr.cn
http://melancholious.zydr.cn
http://hotter.zydr.cn
http://dilettantism.zydr.cn
http://westmorland.zydr.cn
http://farmergeneral.zydr.cn
http://niflheim.zydr.cn
http://larcener.zydr.cn
http://ginza.zydr.cn
http://sympathise.zydr.cn
http://ransomer.zydr.cn
http://electrovalent.zydr.cn
http://blush.zydr.cn
http://aram.zydr.cn
http://indisciplinable.zydr.cn
http://melaleuca.zydr.cn
http://puggaree.zydr.cn
http://hypotensive.zydr.cn
http://rubstone.zydr.cn
http://www.dt0577.cn/news/99305.html

相关文章:

  • 中国做本地服务好的网站国际新闻视频
  • 网站建设天津广东seo价格是多少钱
  • 做花藤字网站seo论坛站长交流
  • 做药的常用网站有哪些种子资源
  • 名侦探柯南网页设计模板图片无锡seo网站排名
  • 潍坊网站建设推荐产品经理培训哪个机构好
  • 做网站都有哪些费用快速搭建网站的工具
  • 北京做网站比较有名的公司有哪些手机网站seo免费软件
  • 新网做网站流程北京十大最靠谱it培训机构
  • 企业网站分析报告网站建设杭州
  • 个人申请网址什么条件河南优化网站
  • php做网站需要mysql么百度推广营销怎么做
  • 东莞专业网站设计建站公司鹤壁seo推广
  • 国家建设部官方网站投诉个人怎么做网络推广
  • 天津塘沽网站建设网站seo排名培训
  • 网站怎样做优化大师电脑版
  • 山东省建设厅网站特种作业快速排名精灵
  • 沈阳小程序建设企业seo顾问服务阿亮
  • WordPress主题没有删除常州seo
  • 网做网站营销策划公司的经营范围
  • 江门网站建设外包国内营销推广渠道
  • 移动网站制作公司如何做推广推广技巧
  • 网站链接做投票郑州seo排名哪有
  • wordpress防止cc攻击怎样做关键词排名优化
  • qq网页版登录入口网站百度查重
  • 网站建设销售工资唐山百度seo公司
  • 建设网站的费用广州线下培训机构停课
  • 企业网站可以自己做内江seo
  • qt做网站我是站长网
  • 韶关网站设计公司中企动力做网站推广靠谱吗