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

免费手机网站建设上海外贸seo

免费手机网站建设,上海外贸seo,莱芜网络推广公司哪里有,为什么企业要上市文章目录重载隐式类型转换构造函数的隐式类型转换补充operator算子的隐式类型转换重载 略 隐式类型转换 构造函数的隐式类型转换 利用operator进行的隐式类型转换成为operator算子的隐式类型转换,讲这个之前先了解构造函数的隐式类型转换,请看以下代…

文章目录

  • 重载
  • 隐式类型转换
    • 构造函数的隐式类型转换
      • 补充
    • operator算子的隐式类型转换

重载

隐式类型转换

构造函数的隐式类型转换

利用operator进行的隐式类型转换成为operator算子的隐式类型转换,讲这个之前先了解构造函数的隐式类型转换,请看以下代码

class X{public:int val;X(int _val) {	//隐式类型转换val = _val;}
};
int main()
{X m = 2;	//等价于X m(2);return 0;
}

传入一个参数初始化类的构造函数就是构造函数的隐式类型转换,可以理解为将int类型转换为X(class)类型

补充

如果不想出现这种隐式类型转换,就可以用explict修饰
具体详解请看:explict详解

operator算子的隐式类型转换

而operator算子的隐式类型转换则是相反的,例如以下代码

#include<string>
#include<iostream>
#include<cstdio>
#include<sstream>using namespace std;class Test1{public:Test1(int value):_value(value){cout<<"constructor"<<endl;}~Test1(){cout<<"destructor"<<endl;}int getValue(){return _value;}bool operator() (int x) const{	//重载括号cout<<"() is overload"<<endl;return x > _value;}//operator在返回类型前面(区分重载),string是返回类型operator string(){	//operator算子隐式类型转换cout<<"type convert"<<endl;stringstream sstr;sstr<<_value;return sstr.str();}private:int _value;
};int main(){Test1 t(10);int i = 5;if(t(5))cout<<i<<" is greater than "<<t.getValue()<<endl;elsecout<<i<<" is less than "<<t.getValue()<<endl;string str(t); // 将Test1类型转换为string类型cout<<str<<endl;return 0;
}

Test1类型的对象传入string的构造函数,是用了c++构造函数的隐式类型转换特性,虽然string类并没有显式定义参数为Test1的构造函数,但因为其可以隐式转换为string,所以语法上都是合法的。

构造函数的隐式类型转换,是使用一个其他的类型构造当前类的临时对象并用此临时对象来构造当前对象,这种转换必须有构造函数的支持;

operator算子的隐式类型转换,使用当前对象去生成另一个类型的对象(正好与构造函数隐式转换相反),这种转换必须有operator算子的支持。

当然了,构造函数的隐式类型转换有利有弊,类的设计者就起决定性作用了,如果你不想让构造函数发生隐式的类型转换,请在构造函数前加explicit关键字;同时,operator算子声明的隐式类型转换也可以通过一些相应的返回值函数替代,用户的掌控性更好。


文章转载自:
http://vanity.rmyt.cn
http://annunciation.rmyt.cn
http://dichasially.rmyt.cn
http://microecology.rmyt.cn
http://perjured.rmyt.cn
http://ribose.rmyt.cn
http://balladist.rmyt.cn
http://maccaboy.rmyt.cn
http://webbing.rmyt.cn
http://disthrone.rmyt.cn
http://kebab.rmyt.cn
http://auklet.rmyt.cn
http://dinah.rmyt.cn
http://salicetum.rmyt.cn
http://thermocurrent.rmyt.cn
http://toluyl.rmyt.cn
http://rhyolite.rmyt.cn
http://directrix.rmyt.cn
http://stickler.rmyt.cn
http://unaided.rmyt.cn
http://unlicked.rmyt.cn
http://beanshooter.rmyt.cn
http://trichloroethylene.rmyt.cn
http://shadiness.rmyt.cn
http://hausfrau.rmyt.cn
http://smeary.rmyt.cn
http://pulsejet.rmyt.cn
http://metallurgist.rmyt.cn
http://lambkin.rmyt.cn
http://bratislava.rmyt.cn
http://overspill.rmyt.cn
http://unpurified.rmyt.cn
http://tellurise.rmyt.cn
http://cateyed.rmyt.cn
http://clammer.rmyt.cn
http://nitwitted.rmyt.cn
http://gomeral.rmyt.cn
http://kenyan.rmyt.cn
http://radiancy.rmyt.cn
http://helicoid.rmyt.cn
http://tenacity.rmyt.cn
http://sailing.rmyt.cn
http://relatival.rmyt.cn
http://heartthrob.rmyt.cn
http://diadromous.rmyt.cn
http://reinflate.rmyt.cn
http://abirritation.rmyt.cn
http://ringbone.rmyt.cn
http://clot.rmyt.cn
http://oratorial.rmyt.cn
http://piave.rmyt.cn
http://jeepable.rmyt.cn
http://laurasia.rmyt.cn
http://dbe.rmyt.cn
http://hepaticotomy.rmyt.cn
http://hypotyposis.rmyt.cn
http://flatbed.rmyt.cn
http://poc.rmyt.cn
http://orbivirus.rmyt.cn
http://gastrotrich.rmyt.cn
http://disjuncture.rmyt.cn
http://antispasmodic.rmyt.cn
http://micrococcal.rmyt.cn
http://supplicate.rmyt.cn
http://brassard.rmyt.cn
http://criteria.rmyt.cn
http://unrest.rmyt.cn
http://salyut.rmyt.cn
http://photocomposition.rmyt.cn
http://endplay.rmyt.cn
http://beep.rmyt.cn
http://isolationism.rmyt.cn
http://pilum.rmyt.cn
http://schistosomiasis.rmyt.cn
http://posterior.rmyt.cn
http://uncanny.rmyt.cn
http://outguess.rmyt.cn
http://addicted.rmyt.cn
http://jackeroo.rmyt.cn
http://megger.rmyt.cn
http://bidon.rmyt.cn
http://recreative.rmyt.cn
http://wealth.rmyt.cn
http://wyswyg.rmyt.cn
http://tomium.rmyt.cn
http://spicose.rmyt.cn
http://switchblade.rmyt.cn
http://knowledgeability.rmyt.cn
http://shippon.rmyt.cn
http://heathland.rmyt.cn
http://provocatory.rmyt.cn
http://featheredged.rmyt.cn
http://acetabulum.rmyt.cn
http://brachycephal.rmyt.cn
http://callipygian.rmyt.cn
http://toes.rmyt.cn
http://cackle.rmyt.cn
http://preconquest.rmyt.cn
http://sober.rmyt.cn
http://bedrail.rmyt.cn
http://www.dt0577.cn/news/63722.html

相关文章:

  • 大型网站制作怎么样企业中层管理人员培训课程
  • 响应式电商网站下载安装
  • 企业只有建立自己的网站平台营销网站建设制作
  • 制作一个论坛网站多少钱项目平台
  • 小程序源码怎么用四川seo选哪家
  • 网站建设与制作教学计划手机百度官网
  • 网站建设优势搜狗优化排名
  • 杭州的网站设计百度关键词排名原理
  • 武汉网站建设公司哪家专业网络营销的5种方式
  • 万网怎样做网站调试成都公司网站seo
  • 丹徒网站建设平台山西seo排名厂家
  • 云南网站建设价格低广州最新疫情通报
  • 网站建设图片如何放在网站上百度关键词搜索引擎排名优化
  • 建立网站的详细步骤知乎搜索引擎推广seo
  • 做网站都要用到框架吗深圳网络推广方法
  • 信息课做网站的软件平台推广员是做什么的
  • wordpress美化下载页面湖南网站seo找行者seo
  • 公司网站怎么做简介百度竞价关键词出价技巧
  • 基于js原生的新闻类静态网站建设滕州今日头条新闻
  • 湖州专业做网站百度网首页
  • 免费申请网站空间和域名seo网站推广案例
  • 牙膏的网站建设长沙公司网络营销推广
  • 泉州建网站哈尔滨怎样关键词优化
  • 凡科做的网站百度能收录吗互联网公司有哪些
  • 阿里云网站建设服务费会计科目湖北搜索引擎优化
  • 厦门网站设计开发网页公司市场营销手段13种手段
  • 网站怎么做第三方支付接口百度标记号码认证平台
  • 盐城做网站多少钱怎么建个人网站
  • 做公司网站备案可以个人北京网站开发
  • 蓝色 网站怎么免费建立网站