A C-style cast is equivalent to try casting in the following order:
const_cast(...)
static_cast(...)
const_cast(static_cast(...))
reinterpret_cast(...)
const_cast(reinterpret_cast(...))
By using static_cast<T>(...)
explicitly we avoid the possibility of an unintentional and dangerous reinterpret_cast
. Furthermore static_cast<T>(...)
allows for easier grepping of casts.
For a more thorough discussion, see “ES.49: If you must use a cast, use a named cast” in the C++ Core Guidelines (Stroustrup & Sutter).