fork download
  1. #include <iostream>
  2.  
  3. class Point {
  4. public:
  5. int x;
  6. int y;
  7.  
  8. Point(int x, int y) : x(x), y(y) {}
  9.  
  10. Point operator+(const Point& other) {
  11. int new_x = x + other.x;
  12. int new_y = y + other.y;
  13. return Point(new_x, new_y);
  14. }
  15.  
  16. void display() {
  17. std::cout << "(" << x << ", " << y << ")" << std::endl;
  18. }
  19. };
  20.  
  21. int main() {
  22. Point point1(1, 2);
  23. Point point2(3, 4);
  24. Point result = point1 + point2;
  25. result.display(); // Выведет (4, 6)
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
(4, 6)