What is the difference between static_cast, dynamic_cast, const_cast, and reinterpret_cast?
Last updated
static_castdoes checked-at-compile-time conversions (numeric, upcasts,void*back to a type).dynamic_castdoes runtime-checked polymorphic downcasts via RTTI, returningnullptror throwingstd::bad_cast.const_castadds/removesconst/volatile(modifying an originally const object is UB).reinterpret_castreinterprets bit patterns and is the most dangerous.Named casts beat C-style casts: they document intent, are grep-able, and restrict allowed conversions.