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

做一个卖车的网站该怎么做承德网络推广

做一个卖车的网站该怎么做,承德网络推广,网络推广员的前景,传奇类网页游戏大全*续上文中的运算符重载 4 重载运算符时,有前置和后置的,运算符重载的函数名都是operator, 无法很好区分 所以c规定,后置重载时,增加一个int形参 与前置做区分 5 重载<<和>>时需要重载为全局函数, 因为重载为成员函数时, this指针默认抢占了第一个形参位, 第一个形参…

*续上文中的运算符重载
4 重载++运算符时,有前置和后置的++,运算符重载的函数名都是operator++, 无法很好区分
所以c++规定,后置++重载时,增加一个int形参 与前置++做区分
5 重载<<和>>时需要重载为全局函数, 因为重载为成员函数时, this指针默认抢占了第一个形参位, 第一个形参位是左侧运算对象,
调用时变成了对象<<cout不符合使用习惯和可读性
重载为全局函数吧ostream\istream 放在第一个形参位就可以了,此时第二个形参位就是当前类的类对象

取地址运算符重载

const成员函数
将const修饰的成员函数称之为 const成员函数,const修饰成员函数放到成员函数参数列表的后面

const实际修饰该陈元函数隐含的this指针, 表面在该成员函数中不能对类的任何成员进行修改
const修饰Data类的print成员函数,printf隐含的指针由data* const this 变为const data* const this

取地址运算符重载(一般情况用不上)

取地址运算符重载分为普通…和const…,一般这两个函数编译器自动生成就够用了
不需要显示实现 存放也特殊场景
比如我们不想让别人取到当前类对象的地址,就可以自己实现一份 随便返回一个地址

日期类的实现
data.h

#pragma once
#include <iostream>
using namespace std;
#include <assert.h>class Data
{//友元声明   可以让类外的函数访问类中的私域//流插入friend ostream& operator<<(ostream& out, const Data& d);//流提取friend istream& operator>>(istream& in, Data& d);//d不能加const因为需要改变
public:Data(int year = 1999, int month = 1, int day = 1);void Print() const;//查看日期是否违法bool CheckData() const;//求每月对应天数int MonthDays(int year, int month) const{assert(month > 0 && month < 13);static int days[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;}return days[month];}Data& operator+=(int day);Data operator+(int day) const;Data& operator-=(int day);Data operator-(int day) const;bool operator<(const Data& d) const;bool operator<=(const Data& d) const;bool operator>(const Data& d) const;bool operator>=(const Data& d) const;bool operator==(const Data& d) const;bool operator!=(const Data& d) const;//++d1(前置++同的较多)Data& operator++();//d1++Data operator++(int);//--d1Data& operator--();//d1--Data operator--(int);int operator-(const Data& d) const;private:int _year;int _month;int _day;
};
//流插入(从左往右插入)  定义为全局函数
ostream& operator<<(ostream& out,const Data& d);
//流提取
istream& operator>>(istream& in,  Data& d);

data.cpp

#define _CRT_SECURE_NO_WARNINGS 1
#include"data.h"
bool Data::CheckData() const
{if (_month < 1 || _month>12|| _day<1 || _day>MonthDays(_year, _month)){return false;}else{return true;}
}
Data::Data(int year, int month, int day)
{_year = year;_month = month;_day = day;if (!CheckData()){cout << "非法日期";Print();}}
void Data::Print() const
{cout << _year << '/' << _month << '/' << _day << endl;
}Data& Data::operator+=(int day)
{if (day < 0){return *this -= - day;}_day += day;while (_day > MonthDays(_year, _month)){_day -= MonthDays(_year, _month);_month++;if (_month == 13){_year++;_month = 1;}}return *this;
}Data Data::operator+(int day) const{Data tmp = *this;tmp += day;return tmp;}Data& Data::operator-=(int day){_day -= day;while (_day <=0 ){--_month;if (_month == 0){_year--;_month = 12;}_day += MonthDays(_year, _month);}return *this;}
Data Data::operator-(int day) const
{Data tmp = *this;tmp -= day;return tmp;
}//也可以实现 +\- 去附用+=\-= 不过效率更低bool Data::operator<(const Data& d) const
{if (_year < d._year){return true;}else if (_year ==d._year){if (_month < d._month){return true;}else if (_month == d._month){return _day < d._day;}}return false;
}
bool Data::operator<=(const Data& d) const
{return *this < d|| *this == d;
}
bool Data::operator>(const Data& d) const
{return !(*this <= d);
}
bool Data::operator>=(const Data& d) const
{return !(*this < d);}
bool Data::operator==(const Data& d) const
{return _year == d._year&& _month == d._month&& _day == d._day;
}
bool Data::operator!=(const Data& d) const
{return !(*this == d);
}//++d1(前置++同的较多)
Data& Data::operator++()
{*this += 1;return *this;
}
//d1++
Data Data::operator++(int)
{Data tmp = *this;*this += 1;return tmp;
}//--d1
Data& Data::operator--()
{*this -= 1;return *this;
}
//d1--
Data Data::operator--(int)
{Data tmp = *this;*this -= 1;return tmp;
}int Data::operator-(const Data& d) const
{int flag = 1;Data max = *this;Data min = d;if (*this < d){max = d;min = *this;flag = -1;}int n = 0;while (min != max){++min;++n;}return n * flag;
}//流插入
ostream& operator<<(ostream& out,const Data& d)
{out << d._year << "年" << d._month << "月" << d._day << "日" << endl;return out;
}
//流提取
istream& operator>>(istream& in, Data& d)
{while (1){cout << "请输入对应的年月日:";in >> d._year >> d._month >> d._day;if (!d.CheckData()){cout << "日期非法,请重新输入日期:"<<endl;d.Print();cout<<endl;}}return in;
}
http://www.hyszgw.com/news/46597.html

相关文章:

  • 青岛做网站哪个最好wordpress 抓别人数据
  • 国企网站建设会议纪要html购物网站源码
  • WordPress插件提示信息网站上不去首页seo要怎么办
  • 网站建设方面的文章做公司网站方案
  • 代码做网站的软件大连网建会
  • 靖江网站设计简单网站建设视频教程下载
  • 小企业网站建设新市场报价湖南公司网站建设
  • 牡丹江市建设工程交易中心网站网站开发 售后服务协议
  • 泰和县城乡建设局网站网站建设流程 费用
  • 小松建设官方网站沧州市青县建设局网站
  • 网站常见问题互联网网站开发
  • 百度xml网站地图全球网站免费空间注册
  • 余姚网站设计平台京东商城网上购物商城
  • 免费网站搭建系统设计网页时有哪些配色方法
  • 青岛鑫隆建设集团网站建设企业银行网站
  • 网站界面设计中的布局设计要注意什么的结合推广页面
  • 网站首页设计外包小程序开发费用一览表
  • 成都网站建设公司创新互联个体工商户做网站
  • 网站建设 好关键词排名哪里查
  • 加盟网站合作如何让wordpress文本小工具支持php和简码?
  • 做的比较好的家具网站首页惠州建设工程质量监督站网站
  • 网站说服力 营销型网站策划开发一个app最少需要多少钱
  • 买医疗产品的网站建设企业网站建设电话
  • 怎么做国内网站广告设计与制作合同范本
  • 网站建设及营销方案公司建立网站步骤
  • 做家居商城网站小说网站怎么做app
  • 互诺 外贸网站建设甘肃省住房和城乡建设部网站
  • 有企业信息的网站网页制作图片居中代码
  • apache 多网站官网做得好的公司
  • wap网站建设学什么07年以前东莞有多乱