-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha.cpp
62 lines (54 loc) · 966 Bytes
/
a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(int x, int y)
{
this->x = x;
this->y = y;
}
Point()
{
x = 0;
y = 0;
}
void show()
{
cout << "x: " << x << " y: " << y << "\n";
}
Point operator+(Point &p);
Point operator-(Point &p);
Point operator+(int num);
};
Point Point::operator+(Point &p)
{
Point res;
res.x = x + p.x;
res.y = y + p.y;
return res;
}
Point Point::operator+(int a)
{
Point res;
res.x = x + a;
res.y = y + a;
return res;
}
Point Point::operator-(Point &p)
{
Point res;
res.x = x - p.x;
res.y = y - p.y;
return res;
}
//When a binary operator is overloaded, the left operand is passed implicitly to the function and the right operand is passed as an argument.
int main()
{
Point a(2, -1), b(-3, 9), c;
c = a + 4;
c.show();
(c + b).show();
return 0;
}