码迷,mamicode.com
首页 > 其他好文 > 详细

转类型转换

时间:2014-10-09 21:26:57      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   使用   ar   sp   div   

reinterpret_cast 这个转换方式在转换指针类型时比较有用

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main(void)
 6 {
 7     int A = 65; // ‘A‘
 8     char * pA = reinterpret_cast<char *>(&A);
 9     cout << *pA << endl;
10     return 0;      
11 }
12 
13 // 显示结果为 A

const_cast 可以转换掉变量的 const 性质,不过不提倡用,因为它的使用预示着设计问题!

另外一条:不要使用C样式的转换语句,不安全,难以跟踪!

转类型转换

标签:style   blog   color   io   os   使用   ar   sp   div   

原文地址:http://www.cnblogs.com/wendellyi/p/4014124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!