As stated previously, the full details are complicated, painful to read, and really only useful to compiler developers, and varies between compilers. Basically, each object contains the following (usually laid out in this order):
- Runtime type information
- Non-Virtual base objects and their data (probably in order of declaration).
- Member variables
- Virtual base objects and their data (Probably in some DFS tree search order).
These pieces of data may or may not be padded to make memory alignment easier etc. Hidden in the runtime type information is stuff about the type, v-tables for virtual parent classes etc, all of which is compiler specific.
When it comes to casts, reinterpret_cast
simply changes the C++ data type of the pointer and does nothing else, so you had better be sure you know what you're doing when you use it, otherwise you're liable to mess things up badly. dynamic_cast
does very much the same thing as static_cast (in altering the pointer) except it uses the runtime type information to figure out if it can cast to the given type, and how to do so. Again, all that is compiler specific. Note that you can't dynamic_cast
a void*
because it needs to know where to find the runtime type information so it can do all its wonderful runtime checks.