When to use reinterpret_cast?

The C++ standard guarantees the following: static_casting a pointer to and from void* preserves the address. That is, in the following, a, b and c all point to the same address: reinterpret_cast only guarantees that if you cast a pointer to a different type, and then reinterpret_cast it back to the original type, you get the original value. So in the following: a and c contain the same value, … Read more

Regular cast vs. static_cast vs. dynamic_cast

static_cast `static_cast` is used for cases where you basically want to reverse an implicit conversion, with a few restrictions and additions. `static_cast` performs no runtime checks. This should be used if you know that you refer to an object of a specific type, and thus a check would be unnecessary. Example: In this example, you … Read more

Casting variables in Java

Casting in Java isn’t magic, it’s you telling the compiler that an Object of type A is actually of more specific type B, and thus gaining access to all the methods on B that you wouldn’t have had otherwise. You’re not performing any kind of magic or conversion when performing casting, you’re essentially telling the … Read more