I am basically wondering how C++ lays out the object in memory. So, I hear that dynamic casts simply adjust the object’s pointer in memory with an offset; and reinterpret kind of allows us to do anything with this pointer. I don’t really understand this. Details would be appreciated!
Share
Each class lays out its data members in the order of declaration.
The compiler is allowed to place padding between members to make access efficient (but it is not allowed to re-order).
How
dynamic_cast<>works is a compiler implementation detail and not defined by the standard. It will all depend on the ABI used by the compiler.reinterpret_cast<>works by just changing the type of the object. The only thing that you can guarantee that works is that casting a pointer to a void* and back to the same the pointer to class will give you the same pointer.