fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point
  5. {
  6. public:
  7. Point() : _x(), _y() {}
  8. Point(int x, int y) : _x(x), _y(y) {}
  9.  
  10. friend int& operator += (int& i, const Point& pt)
  11. {
  12. i += pt._x;
  13. i += pt._y;
  14. return i;
  15. }
  16.  
  17. private:
  18. int _x;
  19. int _y;
  20. };
  21.  
  22. int main()
  23. {
  24. int i = 5;
  25. Point pt(1, 2);
  26. i += pt;
  27. cout << i;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
8