3 ms·
As you said, char* can alias any other type, but that does not allow any other type to alias char*. reinterpret_cast<char*>(T*); // Perfectly fine. rei
by Kranar 5y ago
As you said, char* can alias any other type, but that does not allow any other type to alias char*.
reinterpret_cast<char*>(T*); // Perfectly fine.
reinterpret_cast<T*>(char*); // Undefined behavior.
Otherwise it would be trivial for any type to alias any other type:
reinterpret_cast<T*>(reinterpret_cast<char*>(U*));