“警告:使用旧式铸造”在g ++ [英] "warning: use of old-style cast" in g++
本文介绍了“警告:使用旧式铸造”在g ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用这个C ++代码,
char * a = ;
我收到警告警告:使用旧式铸造
。
新风格的演员会是什么?
解决方案
code> reinterpret_cast , static_cast
, dynamic_cast
const_cast 是c ++的替代方案。
-
const_cast
在多态类型之间进行转换时, -
dynamic_cast
-
static_cast
在继承层次结构中执行例如上/下转换,但没有运行时检查,或者显式执行可能是隐式的转换例如float to int)
c> reinterpret_cast 可以在不相关的类型之间转换。 b $ b
Possible Duplicate:
When should static_cast, dynamic_cast and reinterpret_cast be used?
With this C++ code,
char* a = (char*) b;
I got warning warning: use of old-style cast
.
What would be the new-style cast?
解决方案
reinterpret_cast
, static_cast
, dynamic_cast
and const_cast
are the c++ cast alternatives.
const_cast
to remove const/volatile from a const variable.dynamic_cast
to perform runtime validity checks when casting in between polymorphic typesstatic_cast
to perform e.g up/down-cast in a inheritance hierarchy, but with no runtime checks, or to explicitly perform conversions that could be implicit (e.g. float to int)reinterpret_cast
to convert in between unrelated types.
这篇关于“警告:使用旧式铸造”在g ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文