Guest User

Untitled

a guest
Dec 18th, 2017
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. Child* k = static_cast<Child*>(d); // 0x00C5A618
  2.  
  3. class Mom
  4. {
  5. public:
  6. int a = 1;
  7. };
  8.  
  9. class Dad : public Mom
  10. {
  11. public:
  12. int b = 2;
  13. };
  14.  
  15. class Child : public Dad
  16. {
  17. public:
  18. int c = 3;
  19. };
  20.  
  21. int main()
  22. {
  23. Child* c = new Child; // 0x00C5A618
  24.  
  25. Mom* m = c; // 0x00C5A618
  26. Dad* d = c; // 0x00C5A618
  27.  
  28. Child* k = static_cast<Child*>(d); // 0x00C5A618
  29.  
  30. return 0;
  31. }
  32.  
  33. Possible Memory Layout for a Singly Derived Hierarchy
  34.  
  35. +-------+-----+-----+---+
  36. | Child : Dad : Mom : a |
  37. | | +-----+---+
  38. | | : b |
  39. | +-----------+---+
  40. | : c |
  41. +-----------------------+
  42.  
  43.  
  44. Possible Memory Layout for a Multiply Derived Hierarchy
  45.  
  46. +-------+-----+---+
  47. | Child : Mom : a |
  48. | +-----+---+
  49. | : Dad : b |
  50. | +-----+---+
  51. | : c |
  52. +-----------------+
Add Comment
Please, Sign In to add comment