reinterpret_cast和static_cast的总结
生活随笔
收集整理的這篇文章主要介紹了
reinterpret_cast和static_cast的总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
主要參考:http://blog.csdn.net/querw/article/details/7387594
http://www.cnblogs.com/jerry19880126/archive/2012/08/14/2638192.html
http://www.cnblogs.com/ider/archive/2011/07/30/cpp_cast_operator_part3.html
http://bbs.csdn.net/topics/390249118
關鍵點:
1.reinterpret_cast:?reinterpret“重新解釋”內存類型?
“重新解釋了數據的比特模型,并沒有進行二進制的轉換”
static_cast ?: 編譯時強制轉換,進行安全性檢查、截斷、指針偏移;
2.注意轉換是長對短,下對上;還是短對長,上對下轉
比如
Struct?CBaseX {int?x; } Struct?CBaseY {int?y; } Struct?CDerived:CBaseX,CBaseY{} 進行static_cast<CBaseY*>(&d),//此時進行了指針的偏移,如下圖所示,偏移了baseX的四個字節 //如果是reinterpret_cast則不會進行偏移。轉載于:https://blog.51cto.com/chenfei/1652010
總結
以上是生活随笔為你收集整理的reinterpret_cast和static_cast的总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AngularJS入门心得2——何为双向
- 下一篇: shell timeout