可能重复:When should static_cast, dynamic_cast and reinterpret_cast be used?
使用此C ++代码,
char* a = (char*) b;
我收到警告warning: use of old-style cast
。
什么是新型演员?
[reinterpret_cast
,static_cast
,dynamic_cast
和const_cast
是c ++强制转换。
const_cast
从常量变量中删除const / volatile。dynamic_cast
在多态类型之间进行转换时执行运行时有效性检查>static_cast
在继承层次结构中执行例如上/下转换,但不进行运行时检查,或显式执行可能隐式的转换(例如,从float到int)reinterpret_cast
在不相关的类型之间进行转换。简要语法示例:
char* a = (char*) b;
//would be
char* a = static_cast<char*>(b);
//to remove the warning
阅读本主题,以了解各种风格的C ++样式转换: