C / C++ - Type Casting
static_castperforms no runtime checks. use it in cases like converting
int, etc. Also used in CRTP.
dynamic_cast: used for handling polymorphism. Only used used in inheritence when casting from base class to derived class.
const_cast: can be used to remove or add
constto a variable.
reinterpret_cast: used for reinterpreting bit patterns and is extremely low level, primarily for things like turning a raw data bit stream into actual data or storing data in the low bits of an aligned pointer.
A C-style cast is basically identical to trying out a range of sequences of C++ casts, and taking the first C++ cast that works, without ever considering
dynamic_cast. More powerful as it combines all of
reinterpret_cast, but it's also unsafe.