Explicit type conversions

suggest change


An expression can be explicitly converted or cast to type T using dynamic_cast<T>, static_cast<T>, reinterpret_cast<T>, or const_cast<T>, depending on what type of cast is intended.

C++ also supports function-style cast notation, T(expr), and C-style cast notation, (T)expr.



All six cast notations have one thing in common:

The reinterpret_cast keyword is responsible for performing two different kinds of “unsafe” conversions:

The static_cast keyword can perform a variety of different conversions:

// on some compilers, suppresses warning about x being unused

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents