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:


Explicit type conversions:
* Explicit type conversions

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
83 Explicit type conversions
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype