fork download
  1. #include <iostream>
  2.  
  3. class empty {};
  4. class onebyte {char a;};
  5.  
  6. template<class sub_expr>
  7. class inherit_again : public sub_expr {
  8. public:
  9. inherit_again() =default;
  10. inherit_again(sub_expr rhs) : sub_expr(std::move(rhs)) {}
  11. };
  12.  
  13. template<class l, class r>
  14. class demo : private l, private inherit_again<r> {
  15. };
  16.  
  17. int main() {
  18. std::cout << sizeof(empty)<< '\n';
  19. std::cout << sizeof(onebyte)<< '\n';
  20. std::cout << sizeof(demo<empty, empty>)<< '\n';
  21. std::cout << sizeof(demo<onebyte, empty>)<< '\n';
  22. std::cout << sizeof(demo<empty, onebyte>)<< '\n';
  23. std::cout << sizeof(demo<onebyte, onebyte>)<< '\n';
  24. std::cout << sizeof(demo<empty, demo<onebyte, empty>>)<< '\n';
  25. std::cout << sizeof(demo<demo<empty, empty>, demo<onebyte, empty>>)<< '\n';
  26. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
1
1
2
1
1
2
2
3