Apparently the compiler considers them to be unrelated types and hence reinterpret_cast
is required. Why is this the rule?
Aside from being pointers, unsigned char *
and char *
have nothing in common (EdChum already mentioned the fact that char
, signed char
and unsigned char
are three different types). You could say the same thing for Foo *
and Bar *
pointer types to any dissimilar structures.
static_cast
means that a pointer of the source type can be used as a pointer of the destination type, which requires a subtype relationship. Hence it cannot be used in the context of your question; what you need is either reinterpret_cast
which does exactly what you want or a C-style cast.