转类型转换

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样式的转换语句,不安全,难以跟踪!

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