19.7. 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.

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