- 论坛徽章:
- 0
|
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. |
|