Explicit type conversion

C++ is a strong-typed language. Many conversions, specially those that imply a different interpretation of the value, require an explicit conversion. A cast, or explicit type conversion, is special programming instuction which specifies what data type to treat a variable as (or an intermediate calculation result) in a given expression. Casting will ignore extra information (but never adds information to the type being casted). The C/C++ cast is either "unchecked"(no check is perfomed and when the destination type can not hold the source value the result is undefined) or "bit pattern" (the data is not interpreted at all and just the raw bit pattern is copied). As an example with fundamental data types, a fixed-point float could be cast as an integer, where the data beyond the decimal (or binary) point is ignored.

There are two common casting styles, each outlined below.

C style casting:


C++ style casting:

dynamic_cast <new_type> (expression)
reinterpret_cast <new_type> (expression)
static_cast <new_type> (expression)
const_cast <new_type> (expression)


Bugs Found

Checked Projects
Collected Errors
14 526
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →