fork(2) download
  1. class Foo {
  2. private:
  3. int a;
  4. int b;
  5. public:
  6. Foo(int _a, int _b): a(_a), b(_b){}
  7. Foo operator + (const Foo &other) const {
  8. return Foo(a + other.a, b + other.b);
  9. }
  10. };
  11.  
  12. class Bar {
  13. private:
  14. int a;
  15. int b;
  16. public:
  17. Bar(int _a, int _b): a(_a), b(_b){}
  18. friend Bar operator + (const Bar &l, const Bar &r) {
  19. return Bar(l.a + r.a, l.b + r.b);
  20. }
  21. };
  22.  
  23.  
  24. int main() {
  25.  
  26. const Foo a(1,2);
  27. const Foo b(3,4);
  28. const Foo c = a + b;
  29.  
  30. const Bar d(1,2);
  31. const Bar e(3,4);
  32. const Bar f = d + e;
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty