C++中的几种type cast

来源:互联网 发布:美工和平面设计 编辑:程序博客网 时间:2024/04/28 07:37

static_cast:无条件转换,强制隐式转换,implicit conversion, 例如:non const -> const, int -> double

 

dynamic_cast:有条件转换,进行执行期检验;安全向下转型(safe down casting)决定某对象是否属于继承体系中的某个类型。

 

reinterpret_cst:低级转型,例如:pointer to int (int*) -> int

 

const_cast:将对象的常量性去掉(cast away the constness);