不好意思写错了 是reinterpret_cast,高手过来总结下啊!作者: csoftman 时间: 2012-05-22 10:56
自己顶个,不要沉了啊作者: AD8018 时间: 2012-05-22 10:57
没有 reindivter_cast作者: Moon_Bird 时间: 2012-05-22 11:12
reindivter_cast -> reinterpret_cast 作者: lsnl8480 时间: 2012-05-22 13:01
static_cast 基本类型间的转换
dynamic_cast 类族间的转换
const_cast 取消常量性的转换
reindivter_cast 看你写的这么随意,那这个就是随意转换吧。 作者: sonicling 时间: 2012-05-22 13:27
static_cast<T>(expr) 类似 (T)expr 的显式转换,但是不能用于
1. ptr/ref of derived class to ptr/ref of base class,
2. const to non-const, volatile to non-volatile
3. array to pointer,
4. function to pointer,
5. lvalue to rvalue
dynamic_cast<T>(expr) 主要用于 ptr/ref of derived class to ptr/ref of base class,不能用于
1. null pointer conversion
2. const to non-const, volatile to non-volatile
static_cast 限制里的3 - 5条应该也不准
const_cast<T>(expr) 主要用于 const to non-const, volatile to non-volatile,而且允许static_cast限制里的3 - 5.
reinterpret_cast<T>(expr) 与上面三个不同在于:它和(T)expr行为非常不同,它直接将内存区块按新类型解释,而且允许static_cast限制里的3 - 5.作者: sonicling 时间: 2012-05-22 13:31
补充一点:reinterpret_cast先尝试进行
3. array to pointer,
4. function to pointer,
5. lvalue to rvalue
这三个转换,然后再重新解释。不能用于 const to non-const, volatile to non-volatile作者: sonicling 时间: 2012-05-22 14:02
更正一下:
3. array to pointer,
4. function to pointer,
5. lvalue to rvalue