style cast" in g++

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 types
  • static_cast to perform eg up/down-cast in a inheritance hierarchy, but with no runtime checks, or to explicitly perform conversions that could be implicit (eg float to int)
  • reinterpret_cast to convert in between unrelated types.

  • Read this topic to know about C++ style casts which come in various flavors:

    When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?

    链接地址: http://www.djcxy.com/p/28692.html

    上一篇: C ++多态性:从父类到子类

    下一篇: 风格转换“在g ++中