-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathb.cpp
73 lines (64 loc) · 1.12 KB
/
b.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
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
using namespace std;
class Point
{
int x, y;
public:
Point(int x = 0, int y = 0)
{
this->x = x;
this->y = y;
}
void show()
{
cout << "x: " << x << " y: " << y << "\n";
}
friend Point operator+(Point, int);
friend Point operator+(int, Point); //not possible by member functions(int before object)
friend bool operator==(Point, Point);
friend Point operator++(Point &); //prefix
friend Point operator++(Point &, int); //postfix
};
Point operator+(int a, Point b)
{
Point res;
res.x = b.x + a;
res.y = b.y + a;
return res;
}
Point operator+(Point b, int a)
{
Point res;
res.x = b.x + a;
res.y = b.y + a;
return res;
}
bool operator==(Point a, Point b)
{
return (a.x == b.x) && (a.y == b.y);
}
Point operator++(Point &a)
{
a.x++;
a.y++;
return a;
}
Point operator++(Point &a, int unused)
{
Point pre = a;
a.x++;
a.y++;
return pre;
}
int main()
{
Point a(3);
a.show();
a++;
a.show();
a = 4 + a;
a.show();
a = a + -4;
(++a).show();
return 0;
}