Static cast
C++ type conversion operator
title: "Static cast" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["c++", "type-theory", "articles-with-underscores-in-the-title"] description: "C++ type conversion operator" topic_path: "technology/computing" source: "https://en.wikipedia.org/wiki/Static_cast" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0
::summary C++ type conversion operator ::
In the C++ programming language, static_cast is an operator that performs an explicit type conversion.
Syntax
::code[lang=cpp] static_cast (object); ::
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 static_cast.
The static_cast operator can be used for operations such as:
- converting a pointer of a base class to a pointer of a non-virtual derived class (downcasting);
- converting numeric data types such as enums to ints or floats.
Although static_cast 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 static_cast from a pointer to a class B to a pointer to a derived class D is ill-formed if B is an inaccessible or ambiguous base of D. A static_cast 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.
References
References
- (2009). "Programming: Principles and Practice Using C++". Addison-Wesley.
- Eckel, Bruce. (2000). "Thinking in C++". [[Prentice Hall]].
::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::