Explicit type conversions

suggest change

Introduction

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.

Syntax

Remarks

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
static_cast<void>(x);

Feedback about page:

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



Table Of Contents