手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

C++ reinterpret_cast介绍

时间:2024-11-21 00:10:49

1、reinterpret_cast转化一稍僚敉视个指针为其他类型的指针,这个操作符能够在非相关的类型之间转换,操作结果只是简单的从一个指针到别的指针的二进制拷贝。reinterpret_cast转换成其它类型的目的只是临时的隐藏自己的信息。

C++ reinterpret_cast介绍

2、错误的使用reinterpret_cast很容易导致程序的不安全,只有将转换后的类型值转换回到其原始类型,这样才是正确使用reinterpret_cast方式。

C++ reinterpret_cast介绍

3、如下图所示,此时结果,i与p的值是完全螽啸镥释相同的。reinterpret_cast的作用是说将指针p的值以二进制(位模式)的方式被解释为整型,并赋给i,//i 也是指针,整型指针;一个明显的现象是在转换前后没有数位损失。

C++ reinterpret_cast介绍

4、reinpreter_cast<type-id> (expression)type-id必须是一个指针、引用、算术类型、函数指针或者成员指针,下图给出了实例。

C++ reinterpret_cast介绍

5、在使用之前,想想是否是真的有必要用,因为有时会带来不必要的麻烦。

C++ reinterpret_cast介绍
© 手抄报圈