c++ const_cast and reinterpret_cast

来源:互联网 发布:mac安装win10启动黑屏 编辑:程序博客网 时间:2024/06/04 18:15

const_cast and reinterpret_cast

这两种转换是在编译时刻完成的。但是,不会编译生成任何转换指令,仅仅指导比编译器对待某一变量按照新的类型对待。

const_cast

最常用的地方是将const 指针或引用转换为volatile指针或引用。对于如果指向的对象本来就是const的,会产生undefine行为

reinterpret_cast

将A类型,按B类型对待。1. 将整数转换为任何类型指针2. 将指针转换为整数3. 将A类型指针或引用转换为B类型指针或引用

0 0
原创粉丝点击