fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A_Root {
  5. int rootField;
  6. };
  7.  
  8. struct B_Root {
  9. int rootField;
  10. };
  11.  
  12. struct B_Derived : public B_Root {
  13. int derivedField;
  14. };
  15.  
  16.  
  17. struct C_Root {
  18. C_Root() {
  19. rootField = 924;
  20. };
  21.  
  22. virtual ~C_Root() {
  23. };
  24.  
  25. int rootField;
  26. };
  27.  
  28. struct C_Sibling {
  29. ~C_Sibling() {
  30. printf("called sibling dtor");
  31. };
  32.  
  33. int siblingField;
  34. int siblingField2;
  35. };
  36.  
  37. struct C_Derived : public C_Root, public C_Sibling {
  38. int derivedField;
  39. };
  40.  
  41. int main() {
  42. printf("A_Root: %d\n", sizeof(A_Root));
  43.  
  44. printf("\n");
  45.  
  46. printf("B_Root: %d / B_Derived: %d\n", sizeof(B_Root), sizeof(B_Derived));
  47.  
  48. printf("\n");
  49.  
  50. printf("C_Root: %d / C_Derived: %d / C_Sibling: %d\n", sizeof(C_Root), sizeof(C_Derived), sizeof(C_Sibling));
  51.  
  52. C_Root* derived = (C_Root*)new C_Derived();
  53.  
  54. (*derived).rootField = 3;
  55.  
  56. printf("derived: %d\n", sizeof(derived));
  57.  
  58. printf("rootField: %d\n", (*derived).rootField);
  59.  
  60. delete derived;
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
A_Root: 4

B_Root: 4 / B_Derived: 8

C_Root: 16 / C_Derived: 24 / C_Sibling: 8
derived: 8
rootField: 3
called sibling dtor