I am well aware of the advantage in using static_cast
rather than C-style casting for pointer types.
If the pointer types are incompatible, then:
One advantage which the other two answers didn't mention yet is that static_cast
is much easier to spot. The meaning of parentheses is notoriously overloaded in C++ and it can be difficult to spot evil (or even incorrect) casts. When I see something ending in _cast
though, it's like a mental speed bump: I slow down and carefully check why the type system is being subverted.