Advertisement
Josif_tepe

Untitled

Nov 21st, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. class Point {
  5. private:
  6.     int x, y;
  7. public:
  8.     Point(int _x, int _y) {
  9.         x = _x;
  10.         y = _y;
  11.     }
  12.     void print() {
  13.         cout << x << " " << y << endl;
  14.     }
  15.     Point& operator += (Point p) {
  16.         x += p.x;
  17.         y += p.y;
  18.         return *this;
  19.     }
  20. };
  21. int main(){
  22.     Point p1(1, 2);
  23.     Point p2(1, 3);
  24.    
  25.     p1 += p2;
  26.    
  27.     p1.print();
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement