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
|
#include <iostream>
using namespace std;
class A {
int a;
int b;
public:
A(int a = 100000) {
this->a = a;
}
void setA(int a) { this->a = a; }
int getA() { return this->a = a; }
int operator+ (int data) {
return this->a + data;
}
A& operator= (const A &aa) {
cout << "대입" << endl;
a = aa.a;
return *this;
}
/*int operator + (int data) {
return this->a + data;
}*///연산자 함수를 사용할 때는 본래의 의미를 잃지 말아야 한다
//friend int operator + (const A &aa, int data);
};
//int operator + (a &aa, int data) {
// return aa.a + data;
//}
void main() {
//cout << 3 + 4 << endl;
A aa(10);
//cout << aa.operator+ (4) << endl; //aa. operator + (4) operator+(aa.4)
A bb;
A cc;
cout << aa.getA() << endl;
cout << bb.getA() << endl;
cc = bb = aa;
//cc.operator=(bb.operator= (aa);)
cout << aa.getA() << endl;
cout << bb.getA() << endl;
cout << cc.getA() << endl;
}
|
cs |
'Programming > [C++]' 카테고리의 다른 글
[C++] Overloading(오버로딩) (0) | 2018.03.21 |
---|---|
[C++] 포함 오브젝트(has ~a) (0) | 2018.03.21 |
[C++] Friend Class (프렌드 클래스) (0) | 2018.03.21 |
[C++] 파일 입출력 (0) | 2018.03.21 |
[C++] 소멸자 (0) | 2018.03.21 |