2012年2月14日
摘要: reinterpret_cast <new_type> (expression) :该转换不考虑expression的类型相当于地址空间的从新分配,参见C++标准转换运算符reinterpret_cast。 typedef int (*FunctionPointer)(int); int value = 21; FunctionPointer funcP; funcP = reinterpret_cast<FunctionPointer> (&value); funcP(value); 这个过程编译器都成功的编译通过,不过一旦运行我们就会得到"EXC_ 阅读全文
posted @ 2012-02-14 19:06 Junhv.W 阅读(119) 评论(0) 推荐(0) 编辑
摘要: const_cast转换符是用来移除变量的const或volatile限定符const_cast就可以直接使用显示转换(int*)来代替:#include<iostream> using namespace std;int main() { const int a = 1; //a的值永远不变 const int* t = &a; //t的值永远不变,但是*t可能改变 int* b = const_cast<int*>(t);//效果和int* b = (int*)(t)一样 *b = 2; cout<<a<<"\t" 阅读全文
posted @ 2012-02-14 17:13 Junhv.W 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 在C++中类型转换的类型有:传统转换方式及用户自动转换、const_cast、reinterpret_cast、static_cast、dynamic_cast显然设置这样的语法当然是有他们自己无可替代的作用了,参见C++类型转换方式总结 。在C++中我觉得数据类型是一个比较抽象的概念,我不知道是不是可以这样说:凡是可以用typedef来重命名的类型都可以看成是数据类型typedef short Int16;typedef int Int32;typedef long int64;typedef int* pInt;typedef int& rInt;typedef const int 阅读全文
posted @ 2012-02-14 14:29 Junhv.W 阅读(197) 评论(0) 推荐(0) 编辑