fork download
  1. #include <iostream>
  2.  
  3. struct B1 {};
  4. struct B2 {};
  5. struct D : public B1, B2 {};
  6.  
  7. int main(int argc, char **argv) {
  8. using namespace std;
  9.  
  10. cout << "B1:" << sizeof(B1) << endl;
  11. cout << "B2:" << sizeof(B2) << endl;
  12. cout << "D:" << sizeof(D) << endl;
  13. cout << "D::B1:" << sizeof(D::B1) << endl;
  14. cout << "D::B2:" << sizeof(D::B2) << endl;
  15.  
  16. D d;
  17. cout << &static_cast<B2&>(d) << " , " << &d << endl;
  18. cout << &(B2&)d << " , " << &d << endl;
  19. D da[2];
  20. cout << &static_cast<B2&>(da[0]) << " , " << &da[1] << endl;
  21. cout << &(B2&)da[0] << " , " << &da[1] << endl;
  22. return 0;
  23. }
  24.  
  25.  
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
B1:1
B2:1
D:1
D::B1:1
D::B2:1
0xbfbfc1ab , 0xbfbfc1ab
0xbfbfc1ab , 0xbfbfc1ab
0xbfbfc1a9 , 0xbfbfc1aa
0xbfbfc1a9 , 0xbfbfc1aa