Advertisement
Josif_tepe

Untitled

Nov 21st, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 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.     Point& operator = (Point p) {
  21.         x = p.x;
  22.         y = p.y;
  23.         return *this;
  24.     }
  25. };
  26. int main(){
  27.     Point p1(1, 2);
  28.     Point p2(1, 3);
  29.    
  30.     p1 += p2;
  31.    
  32.     p1.print();
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement