my-server
← Wiki

Static cast

In the C++ programming language, <code>static_cast</code> is an operator that performs an explicit type conversion.

Syntax

The type parameter must be a data type to which object can be converted via a known method, whether it be a builtin or a cast. The type can be a reference or an enumerator. All types of conversions that are well-defined and allowed by the compiler are performed using <code>static_cast</code>.

The <code>static_cast<></code> operator can be used for operations such as:

Although <code>static_cast</code> conversions are checked at compile time to prevent obvious incompatibilities, no run-time type checking is performed that would prevent a cast between incompatible data types, such as pointers. A <code>static_cast</code> from a pointer to a class <code>B</code> to a pointer to a derived class <code>D</code> is ill-formed if <code>B</code> is an inaccessible or ambiguous base of <code>D</code>. A <code>static_cast</code> from a pointer of a virtual base class (or a base class of a virtual base class) to a pointer of a derived class is ill-formed.

See also

References