As a rule, I saw how these types of casts appear in the code when something is no longer being created, perhaps because we started using a new compiler, which is more strict with respect to implicit conversions, so that the key βbenefitsβ from implicit conversions , Obviously, the right thing in this situation is to change the code in some other way!
Dynamic_cast can be used for upstream casting with polymorphism. So, if you have such a structure,
Base β Derivative A
Base β Derivative B
you can do dynamic_cast (b); (b is a pointer to Base, but is actually Derived_B);
If it were not for the Derived_B class, you would get 0 instead of 0 of the converted pointer.
This is much slower than static_cast, since the check is performed at runtime, not compile time, but the intended use is different.
reinterpret_cast simply changes the type label, allowing a funky C-style FX (or "type-punning" is usually called), useful for protocol / low level operation, but should be used sparingly.
Typically, a lot of codes in a code is a sign that something is wrong with your code design.
source share