c++ 之 reinterpret_cast <new_type> (expression) 常见用法
来源:互联网 发布:百度里可以申请域名 编辑:程序博客网 时间:2024/06/05 11:47
参考:http://blog.csdn.net/u013763860/article/details/40857881
reinterpret_cast (expression)
reinterpret_cast是强制类型转换符!他是用来处理无关类型转换的,通常为操作数的位模式提供较低层次的重新解释!但是他仅仅是重新解释了给出的对象的比特模型,并没有进行二进制的转换!
他是用在任意的指针之间的转换,引用之间的转换,指针和足够大的int型之间的转换,整数到指针的转换.
主要用途
从指针类型到一个足够大的整数类型从整数类型或者枚举类型到指针类型从一个指向函数的指针到另一个不同类型的指向函数的指针从一个指向对象的指针到另一个不同类型的指向对象的指针从一个指向类函数成员的指针到另一个指向不同类型的函数成员的指针从一个指向类数据成员的指针到另一个指向不同类型的数据成员的指针
举例说明:
int *pi; char *pc = reinterpret_cast<char*>(pi);
在这里你可以看到reinterpret_cast的强大作用,但是要注意的是,他并没有进行二进制的转换,pc指向的真实对象其实还是int的,不是char~ 。
注意事项:错误的使用reinterpret_cast很容易导致程序的不安全,只有将转换后的类型值转换回到其原始类型,这样才是正确使用reinterpret_cast方式。
补充说明:
reinterpret_cast不能像const_cast那样去除const修饰符。
阅读全文
0 0
- c++ 之 reinterpret_cast <new_type> (expression) 常见用法
- reinterpret_cast <new_type> (expression)
- new_type.c
- dynamic_cast <new_type> (expression)
- static_cast <new_type> (expression)
- c++标准转换运算符 reinterpret_cast <new_type>
- C++ 强制类型转换 static_cast<new_type>(expression)
- 【C/C++学习】之六、reinterpret_cast
- reinterpret_cast用法详述
- 【C/C++学习】之二、static_cast和dynamic_cast、reinterpret_cast
- C- Expression
- 【原创】C指针常见用法
- C语言const常见用法
- C++STL vector常见用法
- Objective-C runtime常见用法
- C++,MessageBox的常见用法
- c++vector类常见用法
- C++vector常见用法总结
- AJAX POST&跨域 解决方案
- Emoji表情在web html上显示
- 验证码的简单封装
- C++中priority_queue的简单用法
- 总结
- c++ 之 reinterpret_cast <new_type> (expression) 常见用法
- 化学结构式检索obabel
- mysql 优化
- 在Anaconda2中使用arcpy站点包
- SDK Build Tools revision (19.0.0) is too low for project Minimum required is 19.1.0
- 用队列实现杨辉三角
- Android 手机卫士(7)AlertDialog
- 将学生的姓名成绩输入到Map中,并用分数排序前三名
- 获取JDBC中的ResultSet的记录的条数