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:
I'm assuming that trivial uses of references to avoid pointers won't count.
In that case: a C-style cast can be:
const_cast
static_cast
static_cast
followed by a const_cast
,reinterpret_cast
reinterpret_cast
followed by a const_cast
with the exception that static_cast
's restrictions on inaccessible base classes are lifted.
const_cast
only applies to pointers and references.
reinterpret_cast
only applies to pointers and references. It does include pointer-to-integer conversions and vice versa, but that still involves a pointer type.
That special exception for static_cast
only applies to pointers and references.
So yes, by excluding pointers and references, you've excluded everything that C-style casts support over a static_cast
.
If yes, is
static_cast
used for non-pointer types only in order to maintain coding consistency?
Let's go with an analogy: I wouldn't use a chainsaw to open a bag of chips. I could, but chainsaws are dangerous, so by using one, I'd introduce unnecessary risks. It's very easy to use a chainsaw wrong, and if I do use it wrong, there's no safety mechanism to prevent accidents.