-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator-example-01.cpp
63 lines (50 loc) · 1.24 KB
/
operator-example-01.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
//
// Created by jaco.ryu on 2019-07-14.
//
#include <iostream>
#include "Power.cpp"
using namespace std;
class Power2 : Power {
public:
Power2(int kick = 1, int punch = 1) {
this->kick = kick;
this->punch = punch;
}
void show();
Power2 operator+(Power2 p);
bool operator==(Power2 p);
Power2& operator+=(Power2 p);
};
void Power2::show() {
cout << "kick=" << this->kick << ", " << "punch=" << this->punch << endl;
}
Power2 Power2::operator+(Power2 p) {
this->kick += p.kick;
this->punch += p.punch;
return *this;
}
bool Power2::operator==(Power2 p) {
return p.punch == this->punch && p.kick == this->kick;
}
Power2& Power2::operator+=(Power2 p) {
this->kick += p.kick;
this->punch += p.punch;
return *this;
}
int main() {
Power2 a(3,5), b(4,6), c, d;
d = a+= b;
d.show();
c = a + b; // 파워 객체 + 연산 a.show();
b.show();
c.show();
a.show();
d.show();
if(a == c) cout << "두 파워가 같다." << endl;
else cout << "두 파워가 같지 않다." << endl;
cout << &a << endl;
cout << &b << endl;
cout << &c << endl; // a와 c는 같은 메모리를 참조 한다.
cout << &d << endl; // d는 복사된다.
return 0;
}