Casts in C++: To lie... and hopefully - to lie usefully
summary
Concrete rules and runnable examples: which cast is zero-cost and static_cast is the go‑to, when to use dynamic_cast for runtime checks, when const_cast is the only way to interoperate with bad APIs, and why reinterpret_cast and C‑style casts invite UB. Slides link includes working links and compile‑time checks, a facet‑based manager demo that stores heterogenous objects and retrieves them with safe downcasts, plus std::bit_cast, any_cast and smart‑pointer cast recipes.
AI-written summary · about
chapters (15)
- 0:00Casting and lies in C++
- 3:34Why lie with casts
- 8:32C++ cast types overview
- 10:16Static cast for safe conversions
- 14:29Static cast in class hierarchies
- 21:15Static cast with void pointers
- 24:07Static cast in constexpr
- 27:40Const cast for const removal
- 37:39Dynamic cast for downcasts
- 44:27Const cast use cases
- 51:53Reinterpret cast for low-level work
- 59:41C-style casts dangers
- 1:02:32Modern C++ casts
- 1:06:06Custom cast-like functions
- 1:08:40Why cast and ethics
related talks
45mBack to Basics: Casting
01h 01mEmbracing PODs Safely Until They Die
12m'Meaningful' casts
58mLeveraging C++20/23 Features for Low Level Interactions
58mUnderstanding and Mastering C++'s Complexity
01h 30mC++ in Constrained Environments
33mC++: Unexpected Behaviour
01h 02mImplicit Conversions Considered Harmful
