Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Empty
  5. {};
  6.  
  7. class Derived1 : public Empty
  8. {};
  9.  
  10. class Derived2 : virtual public Empty
  11. {};
  12.  
  13. class Derived3 : public Empty
  14. {
  15. char c;
  16. };
  17.  
  18. class Derived4 : virtual public Empty
  19. {
  20. char c;
  21. };
  22.  
  23. class Dummy
  24. {
  25. char c;
  26. };
  27.  
  28. int main()
  29. {
  30. //print the size of each class and subclasses
  31. cout << "sizeof(Empty) " << sizeof(Empty) << endl;
  32. cout << "sizeof(Derived1) " << sizeof(Derived1) << endl;
  33. cout << "sizeof(Derived2) " << sizeof(Derived2) << endl;
  34. cout << "sizeof(Derived3) " << sizeof(Derived3) << endl;
  35. cout << "sizeof(Derived4) " << sizeof(Derived4) << endl;
  36. cout << "sizeof(Dummy) " << sizeof(Dummy) << endl;
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement