【C++】 标准运算符
来源:互联网 发布:js 修改style属性 编辑:程序博客网 时间:2024/06/03 15:19
/*static_cast和reinterpret_cast一样,在面对const的时候都无能为力:两者都不能去除const限定。两者也存在的很多的不同,比如static_cast不仅可以用在指针和引用上,还可以用在基础数据和对象上;前面提到过reinterpret_cast可以用在"没有关系"的类型之间,而用static_cast来处理的转换就需要两者具有"一定的关系"了。*/// 实例验证#include <iostream>using namespace std;unsigned short Hash( void *p ){unsigned long val = reinterpret_cast <unsigned long>( p );return ( unsigned short ) ( val ^ (val >> 16) );}class Something{/* Come Codes here */};class Otherthing{/* Come Codes here */};int main(){typedef unsigned short (*FuncPointer) ( void* );FuncPointer fp = Hash; // right,this is what we wantint a[10];const int* ch = a; // right, array is just like pointerchar chArray[4] = {'a','b','c','d'};fp = reinterpret_cast<FuncPointer> (ch); // no arror,but does't make sensech = reinterpret_cast<int*> (chArray);// no errorcout << hex << *ch; // output:64636261// it really reinerpret the pointerSomething *st = new Something();Otherthing *ot = reinterpret_cast<Otherthing*> (st);// cast between objects with on relationshipsystem("pause");return 0;}
阅读全文
0 0
- 【C++】 标准运算符
- C/C++中标准转换运算符reinterpret_cast
- 标准运算符
- C++/C语言的标准库函数与运算符的区别new/delete malloc/free
- C++/C语言的标准库函数与运算符的区别new/delet
- C++/C语言的标准库函数malloc/free与运算符new/delete的区别
- C++/C语言的标准库函数与运算符的区别new/delete malloc/free
- 标准转换运算符static_cast
- 标准查询运算符(SQO)
- C++标准转换运算符
- 19.C#:支持标准查询运算符的集合接口,Linq查询语句
- C语言运算符运算
- 标准c++强制类型转换运算符
- C++标准转换运算符reinterpret_cast
- C++标准转换运算符dynamic_cast
- C++标准转换运算符static_cast
- C++标准转换运算符static_cast
- C++标准转换运算符reinterpret_cast
- shell笔记收藏
- Spring JDBC-事务方法嵌套调用解读
- js判断浏览器与版本号
- 基于rem的移动端布局注意事项
- 移动架构02_UML类图
- 【C++】 标准运算符
- 在一个千万级的数据库查寻中,如何提高查询效率?
- IntelliJ idea在Spring配置无错误时,装配对象出现 Could not autowire. no beans of "XXX" type found
- querystring
- 编程计算1*1+2*2+3*3+…….n*n;
- 奇异值分解(SVD) --- 线性变换几何意义
- 3、实验一结果
- Django blog
- spark_RDD数据操作