fork download
  1. #include <iostream>
  2.  
  3. struct rect {
  4. int x, y, w, h;
  5. };
  6.  
  7. std::ostream& operator<<(std::ostream& os, rect r)
  8. {
  9. return os << r.x << " " << r.y << " " << r.w << " " << r.h << '\n';
  10. }
  11.  
  12. struct A
  13. {
  14. rect bounds;
  15.  
  16. A(int x, int y, int w, int h)
  17. {
  18. std::cout << "O1: " << x << " " << y << " " << w << " " << h << "\n";
  19. bounds = { x,y,w,h };
  20. std::cout << "O2: " << rect(bounds);
  21. }
  22. };
  23.  
  24. struct B : A
  25. {
  26. B(rect bounds) : A(bounds.x, bounds.y, bounds.w, bounds.h)
  27. {
  28. std::cout << "T1: " << rect(bounds);
  29. std::cout << "T2: " << rect(this->bounds) << "\n";
  30. }
  31. };
  32.  
  33. int main()
  34. {
  35. B b({ 300, 200, 200, 200 });
  36. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
O1: 300 200 200 200
O2: 300 200 200 200
T1: 300 200 200 200
T2: 300 200 200 200