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

网站建设原因邯郸网站建设的地方

网站建设原因,邯郸网站建设的地方,北京seo平台,网站底部源码类型转换const_cast、reinterpret_cast、dynamic_cast、static_cast const_castreinterpret_castdynamic_caststatic_cast const_cast 被const修饰的函数可以被访问#xff0c;但是不能被修改成员变量 const_cast可以去掉const #include iostream using namespace s… 类型转换const_cast、reinterpret_cast、dynamic_cast、static_cast const_castreinterpret_castdynamic_caststatic_cast const_cast 被const修饰的函数可以被访问但是不能被修改成员变量 const_cast可以去掉const #include iostream using namespace std;class FHello { public:FHello();void Init();/*const*/ private:int a;int b;float c; }; FHello::FHello() {a 0;b 10;c 20.f; } void FHello::Init()/*const*/ {auto Hello_a [](){cout a endl;};auto Hello_b []()-bool{cout b endl;return true;};Hello_a();if (bool bHello Hello_b()){cout true endl;}else{cout false endl;} } int main() {const FHello* HelloTest new FHello();//HelloTest-Init();因为HelloTest被const修饰了而上面代码中没有用const修饰//用const_cast去掉constFHello* Test const_castFHello*(HelloTest);Test-Init();//编译出错会返回NULL//c风格的强转是万能强转//容易出问题万一转换失败了变成野指针了也不知道少用FHello* NewTest (FHello*)HelloTest;NewTest-Init();delete HelloTest;return 0; } reinterpret_cast 把指针转换成int也可以把int转成指针也可以指针转换成指针 #include iostream using namespace std;class FHello { public:FHello();void Init();/*const*/ private:int a;int b;float c; }; FHello::FHello() {a 0;b 10;c 20.f; } void FHello::Init()/*const*/ {auto Hello_a [](){cout a endl;};auto Hello_b []()-bool{cout b endl;return true;};Hello_a();if (bool bHello Hello_b()){cout true endl;}else{cout false endl;} } int main() {//const_castconst FHello* HelloTest new FHello();FHello* Test const_castFHello*(HelloTest);Test-Init();FHello* NewTest (FHello*)HelloTest;NewTest-Init();//reinterpret_cast//reinterpret_cast,先转换成int再转换成指针int a reinterpret_castint(NewTest);FHello*b reinterpret_castFHello*(a);b-Init();//也可以转换成int*指针也可以转换回来int* a2 reinterpret_castint*(NewTest);FHello* b2 reinterpret_castFHello*(a2);b2-Init();//可以转换成float*指针但是不可以用float类型float* a3 reinterpret_castfloat*(NewTest);FHello* b3 reinterpret_castFHello*(a3);b3-Init();delete HelloTest;return 0; }dynamic_cast 动态的转化可以向上转化也可以向下转化 向上转化和向下转化的意思是在数层的继承关系中可以向父类或派生类进行转化 向下转换时会进行类型检测如果类型无法转换回返回NULL。是一个比较安全的转换 接口父类必须有虚函数否则会报错 #include iostream using namespace std;class FHello { public:FHello();virtual ~FHello();void Init();/*const*/ private:int a;int b;float c; }; FHello::FHello() {a 0;b 10;c 20.f; } FHello::~FHello() {} void FHello::Init()/*const*/ {auto Hello_a [](){cout a endl;};auto Hello_b []()-bool{cout b endl;return true;};Hello_a();if (bool bHello Hello_b()){cout true endl;}else{cout false endl;} }class FHello1:public FHello { public:void Hello1temp() {} private:int a; };class FHello2 :public FHello1 {};int main() {//const_castconst FHello* HelloTest new FHello();FHello* Test const_castFHello*(HelloTest);Test-Init();FHello* NewTest (FHello*)HelloTest;NewTest-Init();//reinterpret_castint a reinterpret_castint(NewTest);FHello*b reinterpret_castFHello*(a);b-Init();int* a2 reinterpret_castint*(NewTest);FHello* b2 reinterpret_castFHello*(a2);b2-Init();float* a3 reinterpret_castfloat*(NewTest);FHello* b3 reinterpret_castFHello*(a3);b3-Init();//dynamic_castFHello* h1 new FHello1();//这一步也是向上转换//向下转换FHello1* A dynamic_castFHello1*(h1);A-Hello1temp();//向上转换,用的少因为有更简单的方法如上FHello* B dynamic_castFHello*(A);B-Init();FHello* B2 A;//进行隐式转换FHello2* FHA2 dynamic_castFHello2*(h1);//转换失败输出NULLif (FHA2){}delete HelloTest;delete h1;return 0; }static_cast 可以向上转化也可以向下转化 向下转换时不安全 static_cast不可以转换const、volitale、_unaligned static_cast和dynamic_cast相比static_cast可以没有虚函数而dynamic_cast必须有虚函数 格式 FHello* Astatic_castFHello*(B);
http://www.pierceye.com/news/1495/

相关文章:

  • 电子商务网站建设课设网站河南便宜网站建设
  • 娄底市网站建设湖南城乡建设部网站首页
  • 莱芜市网站建设设计导购网站开发 源码
  • 无锡商城网站建设提高网站转化率
  • 自己做网站优化微信朋友圈怎么发链接那种网页怎么制作
  • 自己做盗版影视网站网络开发定制
  • 高端企业网站制作网站建设市场拓展岗位
  • 电子商务网站的分类wordpress redis 刷新
  • 站长工具seo综合查询怎么看数据哪个网站可以做免费推广
  • 怎么做刷题网站无锡做网站哪里好
  • 南京高新区规划建设局网站网站用什么图片格式好
  • 徐州网站建设系统深圳租赁住房和建设局网站
  • 购物网站两化融合建设项目报告永久免费自助网站
  • 建设一个网站平台需要哪些技术员一个企业该如何进行网络营销
  • 开封市住房和城乡建设局网站潍坊做网站的网络公司
  • 网站 后台 安装做视频网站服务器多少钱
  • 江西省建设监理网站湖南建立网站营销设计
  • 个人简历模板免费网站网站域名如何更换
  • 济南做网站的高端品牌wordpress需要登录
  • 小型网站如何做网站开发一般用
  • 正能量网站入口不用下载免费友链大全
  • 赣州网站网站建设网站开发一般要多少钱
  • 美容养生连锁东莞网站建设网站主动服务方案
  • 建设银行网站登录不了网络营销与管理专业
  • 网站的总体方案html怎么做成网站
  • 游戏网站交换友情链接报表网站建设
  • 网站的建设求职简历网页设计宣传推广方案
  • 建筑公司网站建设官网服务器
  • 什么网站可以在线做考教师岗位的题网站开发者工具
  • 专门做家纺的网站asp网站设置