fork download
  1. #include <iostream>
  2.  
  3. struct Foo
  4. {
  5. int x;
  6. int y;
  7. };
  8.  
  9. struct Bar: public Foo
  10. {
  11. int another_x;
  12. };
  13.  
  14. struct Baz: public Foo
  15. {
  16. int another_y;
  17. };
  18.  
  19. void someFunction(const Foo &foo)
  20. {
  21. std::cout << foo.x << '\n';
  22. std::cout << foo.y << '\n';
  23. };
  24.  
  25. int main(int argc, char **argv)
  26. {
  27. Bar a;
  28. Baz b;
  29.  
  30. a.x = 0;
  31. a.y = 1;
  32. b.x = 2;
  33. b.y = 3;
  34.  
  35. someFunction(a);
  36. someFunction(b);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
0
1
2
3