static_cast:    这种强制转换只会在编译时检查。 如果编译器检测到您尝试强制转换完全不兼容的类型,则static_cast会返回错误。 您还可以使用它在基类指针和派生类指针之间强制转换,但是,编译器在无法分辨此类转换在运行时是否是安全的。

dynamic_cast: dynamic_cast在运行时检查基类指针和派生类指针之间的强制转换。 dynamic_cast 是比 static_cast 更安全的强制类型转换,但运行时检查会带来一些开销。

const_cast:    const_cast转换为 const 的变量,或者将非 const 变量转换为 const。 通过使用这个操作符强制转换 const 就像使用C样式转换一样容易出错,不同之处在于使用const-cast 不太可能意外地执行转换。 有时候你只能强制转换 const 的变量,例如,传递 const 变量到一个非 const 参数的函数中。

 void Func(double& d) { ... }
void ConstCast()
{
const double pi = 3.14;
Func(const_cast<double&>(pi)); //No error.
}

const_cast

reinterpret_cast : 允许将任何指针转换为任何其他指针类型。 也允许将任何整数类型转换为任何指针类型以及反向转换。

 const char* str = "hello";
int i = static_cast<int>(str);//error C2440: 'static_cast' : cannot
// convert from 'const char *' to 'int'
int j = (int)str; // C-style cast. Did the programmer really intend
// to do this?
int k = reinterpret_cast<int>(str);// Programming intent is clear.
// However, it is not 64-bit safe.

reinterpret_cast

最新文章

  1. CSS currentColor 变量的使用
  2. 使用WordPress搭建自己的博客
  3. uboot 、内核、文件系统移植
  4. MTK Android 编译命令
  5. 对golang服务器开发模式的一些思考
  6. http 协议的过程
  7. v3学院带您一起学习FPGA
  8. 2017/4/26-DOM解析XML文件
  9. webapp通用选择器:iosselect
  10. Flume报 Space for commit to queue couldn&#39;t be acquired. Sinks are likely not keeping up with sources, or the buffer size is too tight
  11. 认识Python和基础知识
  12. Java实现产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。
  13. mybatis 中的 xml 配置文件中 ‘&lt;’、 ‘&gt;’ 处理
  14. CF1107
  15. [js高手之路]深入浅出webpack教程系列2-配置文件webpack.config.js详解(上)
  16. git找回本地误删的文件
  17. vip导致的serverConnection closed by foreign host问题
  18. leetCode题解之Longest Palindrome
  19. Codeforces 429B Working out(递推DP)
  20. Linux shell 执行修改配置文件中的内容

热门文章

  1. idea的有些路径问题
  2. bzoj 3612 [Heoi2014]平衡——整数划分(dp)
  3. FPGA层次结构和复位策略
  4. Stratix IV内嵌DPA电路的基本结构
  5. docker 及 linux 初接触
  6. thinkphp中的volist标签
  7. 张瀚荣:如何用UE4制作3D动作游戏
  8. python学习(二) 列表和元组
  9. 动态代理AOP实现方法过滤
  10. 易酷cms本地包含漏洞拿shell