-
Notifications
You must be signed in to change notification settings - Fork 1
/
gcbase.h
50 lines (43 loc) · 905 Bytes
/
gcbase.h
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
#ifndef GCBASE_H
#define GCBASE_H
class A {
public:
A() {
count = new int(1);
}
A(const A& rhs) {
if(count != nullptr) {
*count -= 1;
if(*count == 0) {
cout << "delete object" << endl;
delete count;
}
}
count = rhs.count;
*count += 1;
}
~A() {
*count -= 1;
if(*count == 0) {
cout << "delete object" << endl;
delete count;
}
}
A& operator=(const A& rhs) {
if(count != nullptr) {
*count -= 1;
if(*count == 0) {
cout << "delete object" << endl;
delete count;
}
}
count = rhs.count;
*count += 1;
}
int GetRefCount() const {
return *count;
}
private:
int *count = nullptr;
};
#endif // GCBASE_H