본문으로 바로가기

[C++]깊은 대입연산자함수

category 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;
  *= *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()constreturn *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


'C++' 카테고리의 다른 글

[JAVA][instanceof 보자]  (1) 2018.03.22
C++setw()=함수  (0) 2018.03.21
[C++] operator 함수  (0) 2018.03.21
스 택 Q  (0) 2018.03.21
◈ 오버로딩이 불가능한 연산자의 종류  (0) 2018.03.21