Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Child* k = static_cast<Child*>(d); // 0x00C5A618
- class Mom
- {
- public:
- int a = 1;
- };
- class Dad : public Mom
- {
- public:
- int b = 2;
- };
- class Child : public Dad
- {
- public:
- int c = 3;
- };
- int main()
- {
- Child* c = new Child; // 0x00C5A618
- Mom* m = c; // 0x00C5A618
- Dad* d = c; // 0x00C5A618
- Child* k = static_cast<Child*>(d); // 0x00C5A618
- return 0;
- }
- Possible Memory Layout for a Singly Derived Hierarchy
- +-------+-----+-----+---+
- | Child : Dad : Mom : a |
- | | +-----+---+
- | | : b |
- | +-----------+---+
- | : c |
- +-----------------------+
- Possible Memory Layout for a Multiply Derived Hierarchy
- +-------+-----+---+
- | Child : Mom : a |
- | +-----+---+
- | : Dad : b |
- | +-----+---+
- | : c |
- +-----------------+
Add Comment
Please, Sign In to add comment