19.8. Safer Typecasting Using ANSI C++ Typecasts

[ fromfile: types.xml id: ansicast ]

ANSI C++ adds four cast operators, with template-style syntax, that more clearly express the intentions of the programmer, and make casts easier to spot in the code.

Table 19.3.  ANSI Typecasts

static_cast<type>(expr) for converting between related types
const_cast<type> expr for casting away const or volatile
dynamic_cast<type>(expr) for safe navigation through an inheritance hierarchy
reinterpret_cast<type>(expr) for type conversions of pointers between unrelated types