Chapter Contents

Previous

Next
Pointer Qualification Conversions, Casts, and Run-Time Type Identification

Cast Operators

This release of the C++ translator supports several new cast operators. These operators are defined in the ISO C++ draft as improved alternatives to the old cast operators, for example, (type)(expr) or type_name (expr) . For more information on these operators, see Stroustrup's Design and Evolution of C++.

The new cast operators are

static_cast< type > ( expr )

portable conversions that do not cast away constness

const_cast< type > ( expr )

pointer qualification conversions, including the unsafe conversions which cannot be performed implicitly

reinterpret_cast< type > ( expr )

nonportable conversions such as:

dynamic_cast< type > ( expr )

run-time type dependent pointer and reference conversions.

The new cast operators, except dynamic_cast , provide separate components of the functionality of the old casts that allow improved type checking. Any old-style cast can be expressed as a combination of the new casts. The new cast operators, other than const_cast , are not allowed to cast away constness on pointer, pointer to member, and reference conversions. See section 5.2.11 of the ISO draft for more information.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.