The basics: Primer on C++ Type Casting

In C++ we usually deal with 6 types of type casting: implicit type cast explicit type cast static_cast dynamic_cast reinterpret_cast const_cast For the sake of my discussion, I’ll exclude const_cast upfront. const_cast sets/unsets the const-ness of a pointer, and it has limited security implication. For the remaining 5 types of casts, it’s useful to put them in a table for easy reference: Now let’s dive into each: ...

July 8, 2024 · 2 min · 753 words · Ao Zhang