C++
[C++]깊은 대입연산자함수
우주 코더
2018. 3. 21. 03:07
the space coding

[C++]깊은 대입연산자함수
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 |
#include<iostream>
using namespace std;
class A
{
int *p;
public:
A()
{
p=new int;
*p=0;
}
~A(){ delete p; }
A(const A &aa)
{
p=new int;
*p = *aa.p;
}
A& operator=(const A &aa)
{
if(this == &aa) return *this;
delete p;
p=new int;
*p=*aa.p;
return *this;
}
void setA(int data){ *p=data; }
int getA()const{ return *p; }
};
void main()
{
A aa;
A bb;
aa.setA(90);
cout<<aa.getA()<<endl;
cout<<bb.getA()<<endl;
bb = aa;
cout<<aa.getA()<<endl;
cout<<bb.getA()<<endl;
} |
cs |