Back to results for “Casting & Conversions”
C++ › Casting & Conversions

What are the four C++ named casts?

Beginner

Answer

C++ provides static_cast (compile-time, related-type conversions), dynamic_cast (safe downcasting in polymorphic hierarchies, checked at runtime), const_cast (add/remove const/volatile), and reinterpret_cast (low-level bit reinterpretation). They replace the C-style cast with clearer intent and safer, more searchable conversions.
double d = static_cast<double>(5);
Base* b = ...; Derived* dd = dynamic_cast<Derived*>(b);
Real-world example Code review requires named casts so each conversion's intent and risk is explicit and greppable.

Common follow-ups: Why prefer named casts over C-style? | Which cast is runtime-checked?