1 Class_singleton
ํด๋์ค์์ this์ ์๋ฏธ ์์ฑ์ ๋ณต์ฌ์์ฑ์ ์ด๋์์ฑ์ ์๋ฉธ์ static (+ ์ฑ๊ธํค)
ํด๋์ค
ํด๋์ค์ ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ
ํด๋์ค์ ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ๋ ๋ฉค๋ฒ๋ณ์์ ํฌ๊ธฐ์ ๋์ผํ๋ค.
๋ฉค๋ฒํจ์๋ ํด๋์ค๋ฅผ ์ด์ฉํ์ฌ ์์ฑํ ๊ฐ์ฒด์ ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
๋จ, ์์์ ์ฌ์ฉํ๋ฉด์ ๊ฐ์ํจ์๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ค๋ฅด๊ฒ ๋์จ๋ค.
๊ธฐ๋ณธ ์์ฑ์, ์๋ฉธ์ (+ this)
์์ฑ์์ ์๋ฉธ์๋ ํด๋์ค ์ด๋ฆ๊ณผ ๊ฐ์ ์ด๋ฆ์ ํจ์์ด๋ค.
๋ฐํ ํ์
์์ด, ์ด๋ฆ๊ณผ ์ธ์๋ง์ผ๋ก ์ ์ธํ๋ค.
์์ฑ์๋ ์ค๋ฒ๋ก๋ฉ์ด ๊ฐ๋ฅํ์ง๋ง ์๋ฉธ์๋ ์ธ์ ์๋ ํํ๋ง ์กด์ฌํ๋ค.
- ์์ฑ์: ์ด ํด๋์ค๋ฅผ ์ด์ฉํด์ ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ์๋์ผ๋ก ํธ์ถ ๋๋ ํจ์.
- ์๋ฉธ์: ์ด ํด๋์ค๋ฅผ ์ด์ฉํด์ ์์ฑํ ๊ฐ์ฒด๊ฐ ๋ฉ๋ชจ๋ฆฌ์์ ์ ๊ฑฐ๋ ๋ ์๋์ผ๋ก ํธ์ถ ๋๋ ํจ์.
ํด๋์ค์์ this์ ์๋ฏธ
ํด๋์ค์ ์ผ๋ฐ ๋ฉค๋ฒํจ์(์ผ๋ฐ ๋ฉค๋ฒํจ์, ์์ฑ์, ์๋ฉธ์) ๋ด๋ถ์์๋ this
๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
this๋ ์๊ธฐ ์์ ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์์ด๋ค.
test1.Output();
์ด๋ฐ์์ผ๋ก ํด๋์ค์ ๋ฉค๋ฒํจ์๋ฅผ ํธ์ถํ ๋, ๊ฐ์ฒด๋ฅผ ์ด์ฉํด์ ํธ์ถํ๊ฒ ๋๋๋ฐ
ํธ์ถํ๋ ์๊ฐ this๋ test1์ ์ฃผ์๋ฅผ ๊ฐ์ง๊ฒ ๋๊ณ ,
test2.Output();
์ผ๋ก ํธ์ถํ๋ฉด ํธ์ถํ๋ ์๊ฐ this๋ test2์ ์ฃผ์๋ฅผ ๊ฐ์ง๊ฒ ๋๋ค.
๐ก ๋ฉค๋ฒํจ์ ๋ด๋ถ์์ ํด๋์ค ๋ฉค๋ฒ๋ณ์๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ์์
this->
๊ฐ ์๋ต๋ ๊ฒ์ด๋ค.
// printf(โthis Test = %pโ, &this); // &this ๋ ์๋ฌ๊ฐ ๋จ. this๋ ๋ณ์๊ฐ ์๋. ๋ง์ฝ ๋ณ์์๋ค๋ฉด, sizeof ํด๋์ค ํฌ๊ธฐ ๊ตฌํ์ ๋ this์ ๋ณ์ ํฌ๊ธฐ๊น์ง ํฌํจ๋์ด ๊ณ์ฐ๋์์ ๊ฒ.
// ์ง์ ๋ฉค๋ฒ๋ณ์์ ์ ๊ทผํ๊ฒ ๋๋ฉด, ํด๋์ค ๋ณ์๋ฅผ nullptr ๋ก ์ด๊ธฐํ ํ์ ๊ฒฝ์ฐ, ์๋ฌ๊ฐ ๋จ. this๋ nullptr ์ด๋๊น. // (printf(โAttack : %dโ, mAttack); ํน์ this->mAttack ~~~ ์ด๋ ๊ฒ ํ๋ค๋ ์๋ฆฌ)
memset
๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ํ๋ ๊ฐ์ผ๋ก ์ฑ์์ค ๋ ์ฌ์ฉ.
๋จ, ์ฑ์ฐ๋ ๋จ์๋ โ1๋ฐ์ดํธ ๋จ์โ๋ก ๊ฐ์ ์ฑ์์ค๋ค!
1๋ฒ ์ธ์์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ, 2๋ฒ ์ธ์์ ๊ฐ์ผ๋ก, 3๋ฒ ์ธ์์ ํฌ๊ธฐ๋งํผ ์ฑ์์ค๋ค.
memset(mArray, 0, sizeof(int) * 10);
1
2
int number = 10;
memset(&number, 1, sizeof(int)); // ๊ฒ๋ ํฐ ๊ฐ ๋์ด.
memset์ โ1๋ฐ์ดํธ ๋จ์โ๋ก ๊ฐ์ ์ฑ์ฐ๊ฒ ๋จ.
int๋ 4๋ฐ์ดํธ ์ด๋ฏ๋ก 1๋ฐ์ดํธ ๋จ์๋ก ๊ฐ์ ์ฑ์ฐ๊ฒ ๋๋ฉด
| 0000 0001 | 0000 0001 | 0000 0001 | 0000 0001 |
์ด๋ ๊ฒ ๋ค์ด๊ฐ๊ฒ ๋์ด์.
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// main.cpp
struct FPlayer
{
char Name[32] = {};
int Attack = 0;
};
class CTest
{
public:
CTest() : // ์ด๋์
๋ผ์ด์ ๋ฅผ ์ด์ฉํด์ ๋ฉค๋ฒ๋ณ์์ ๊ฐ์ ์ ์ธ๊ณผ ๋์์ ์ด๊ธฐํํ ์ ์๋ค.
mAttack(20),
mDefense(10)
{
// ์๋๋ mAttack ๋ณ์๊ฐ ์ ์ธ์ด ๋ ํ์ 50์ ๋์
ํ๋ค.
mAttack = 50;
memset(mArray, 0, sizeof(int) * 10);
printf("CTest ์์ฑ์\n");
}
~CTest()
{
}
// CTest test2("๋ฐ๋ณด"); ์ด ์ค์์ ํธ์ถ๋๋๋ก ๋ง๋ ์์ฑ์์ง๋ง,
// ์ด๋์
๋ผ์ด์ mName(Name) ๋๋ ์์ฑ์ ๋ด๋ถ์ mName = Name; ์ผ๋ก ์์ ํ ์ ์์.
CTest(const char* Name) :
mAttack(30),
mDefense(40)
{
printf("CTest const char* ์์ฑ์\n");
}
void Output()
{
printf("this = %p\n", this);
printf("๊ณต๊ฒฉ๋ ฅ : %d\n", mAttack);
printf("๋ฐฉ์ด๋ ฅ : %d\n", this->mDefense);
//printf("this Addr = %p\n", &this); // <- ์๋ฌ.
}
public:
// ์ด ์๋๋ก ๋ค๋ฅธ ์ ๊ทผ์ ์ด ํค์๋๋ฅผ ๋ง๋๊ธฐ ์ ๊น์ง ๋ชจ๋ public์ด ๋๋ค.
char mName[32] = {};
int mAttack = 0;
int* mArray = nullptr;
private:
int mDefense = 0;
};
void OutputPlayer(FPlayer* Player)
{
printf("๊ณต๊ฒฉ๋ ฅ : %d\n", Player->Attack);
}
int main()
{
FPlayer Player; // ๊ตฌ์กฐ์ฒด ๋ณ์ ์ ์ธ
Player.Attack = 10;
OutputPlayer(&Player);
CTest test1, test2("์ด๋ฆ");
printf("test1 = %p\n", &test1); // test1์ ์ฃผ์ ์ถ๋ ฅ
printf("test2 = %p\n", &test2); // test2์ ์ฃผ์ ์ถ๋ ฅ
// Output ๋ฉค๋ฒํจ์๋ test1๊ณผ test2 ๋ชจ๋ ๋์ผํ ์ฃผ์์ ํจ์๋ฅผ
// ์ฌ์ฉํ๊ฒ ๋๋ค. ๊ทธ๋ฐ๋ฐ ๋ฉค๋ฒํจ์์์ ์ ํํ๊ฒ test1๊ณผ test2์
// ๋ฉค๋ฒ๋ณ์์ ๊ฐ์ ์ธ์ํ๊ณ ์ฌ์ฉํ ์ ์๋ค.
test1.mAttack = 100;
test1.Output();
test2.mAttack = 300;
test2.Output();
return 0;
}
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
class CPlayer
{
/*
์์ฑ์์ ์๋ฉธ์๋ ํด๋์ค ์ด๋ฆ๊ณผ ๊ฐ์ ์ด๋ฆ์ ํจ์์ด๋ค.
๋ฐํ ํ์
์์ด ์ด๋ฆ๊ณผ ์ธ์๋ง์ผ๋ก ์ ์ธํ๋ค.
์์ฑ์๋ ์ค๋ฒ๋ก๋ฉ์ด ๊ฐ๋ฅํ์ง๋ง ์๋ฉธ์๋ ์ธ์ ์๋ ํํ๋ง ์กด์ฌํ๋ค.
์์ฑ์ : ์ด ํด๋์ค๋ฅผ ์ด์ฉํด์ ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ์๋์ผ๋ก ํธ์ถ์ด ๋๋
ํจ์์ด๋ค.
์๋ฉธ์ : ์ด ํด๋์ค๋ฅผ ์ด์ฉํด์ ์์ฑํ ๊ฐ์ฒด๊ฐ ๋ฉ๋ชจ๋ฆฌ์์ ์ ๊ฑฐ๋ ๋ ์๋์ผ๋ก
ํธ์ถ์ด ๋๋ ํจ์์ด๋ค.
*/
public:
// ์์ฑ์
// ์ด๋์
๋ผ์ด์ ๋ฅผ ์ด์ฉํด์ ๋ฉค๋ฒ๋ณ์์ ๊ฐ์ ์ ์ธ๊ณผ ๋์์ ์ด๊ธฐํํ ์ ์๋ค.
CPlayer() :
mAttack(20),
mDefense(10)
{
// ์๋๋ mAttack ๋ณ์๊ฐ ์ ์ธ์ด ๋ ํ์ 50์ ๋์
ํ๋ค.
mAttack = 50;
// ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ํ๋ ๊ฐ์ผ๋ก ์ฑ์์ค ๋ ์ฌ์ฉ
// ๋จ, ์ฑ์ฐ๋ ๋จ์๋ '๋ฐ์ดํธ ๋จ์'๋ก ๊ฐ์ ์ฑ์์ค๋ค!
// 1๋ฒ ์ธ์์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ, 2๋ฒ ์ธ์์ ๊ฐ์ผ๋ก, 3๋ฒ ์ธ์์ ํฌ๊ธฐ๋งํผ ์ฑ์์ค๋ค.
memset(mArray, 0, sizeof(int) * 10);
printf("CPlayer ์์ฑ์\n");
}
CPlayer(const char* Name) :
mAttack(30),
mDefense(40)
{
printf("CPlayer const char* ์์ฑ์\n");
}
/*
๋ณต์ฌ์์ฑ์ : ๋ค๋ฅธ ๊ฐ์ฒด๋ฅผ ๋ณต์ฌํ ์๋ก์ด ๊ฐ์ฒด๋ฅผ ๋ง๋ค ๋ ์ฌ์ฉํ๋ค.
์ด๋์์ฑ์ : ๋ค๋ฅธ ๊ฐ์ฒด๊ฐ ๊ฐ์ง๊ณ ์๋ ๋ด์ฉ์ ์๋ก์ด ๊ฐ์ฒด๋ก ์ฎ๊ฒจ์ฃผ๋ฉด์
๊ฐ์ฒด๋ฅผ ๋ง๋ค ๋ ์ฌ์ฉํ๋ค.
ํด๋์คํ์
&&
RValue ํ์
์ด๋ผ๊ณ ํ๋ค.
int& test = number + 10; // ์์๊ฐ์ฒด ์ฐธ์กฐ ์ ๋จ
int&& test = number + 10; // ์์๊ฐ์ฒด ์ฐธ์กฐ ๋จ
*/
/*
์์๋ณต์ฌ: ํด๋์ค์ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ๋ณต์ฌํ๋ค. ์ฃผ์๊ฐ๊น์ง ๋์ผํ๊ฒ. ๊ทธ๋์ ๋ณต์ฌํ ์ฌ๋ฌ ๊ฐ์ฒด๊ฐ ์์ ๋, ๋ชจ๋ ์ญ์ ํ๋ค๋ฉด-... ์ญ์ ํ ๊ฑธ ๋ ์ญ์ ํ๊ฒ ๋๋ ์ผ ๋ฐ์
๊น์๋ณต์ฌ:
*/
CPlayer(const CPlayer& ref)
{
// ์์ ๋ณต์ฌ. ref์ ๋ค์ด์จ ๊ฐ์ฒด๋ฅผ, this*๊ฐ ๊ฐ๋ฆฌํค๋ ๋ณ์์ ๋์
ํด๋ฒ๋ฆฌ๋ ๊ฒ์.
// this*๋, ๋ฐ์์ ์์ฑํ .. CPlayer copyTest(Player1); ์์ copyTest ๋ณ์์ธ๊ฑฐ์.
//*this = ref;
mArray = new int[10];
// ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ณต์ฌํ ๋ ์ฌ์ฉ.
// 1๋ฒ ์ธ์์ ์ฃผ์์, 2๋ฒ ์ธ์์ ์ฃผ์๋ก๋ถํฐ 3๋ฒ ์ธ์์ ๋ค์ด๊ฐ๋ ๋ฐ์ดํธ ์ ๋งํผ์ ๋ณต์ฌํด์ค.
// memcpy
memcpy(mArray, ref.mArray, sizeof(int) * 10);
/* ์ด๊ฒ๋ณด๋จ memcpy๋ฅผ...
for (int i = 0; i < 10; i++)
{
mArray[i] = ref.mArray[i];
}
*/
}
// ์ด๋์์ฑ์. ์ด๊ฑฐ ์์ฑํ๋ ์๊ฐ, ์์ ๋ณต์ฌ์์ฑ์์์ ์์ ๋ณต์ฌ๋ก ์ผ๋ *this = ref; ๋ฅผ ๋ชป์ฐ๊ฒ ๋จ.
// ์์ฑ์ ํธ์ถ๋๊ณ ์ด๋ฌ๋ ๋ถ๋ถ๋ค ๋ฉด์ ์ ๋ง์ด ๋์จ๋จ๋ค.
CPlayer(CPlayer&& ref)
{
}
// ์๋ฉธ์
~CPlayer()
{
printf("CPlayer ์๋ฉธ์\n");
}
public:
// ์ด ์๋๋ก ๋ค๋ฅธ ์ ๊ทผ์ ์ด ํค์๋๋ฅผ ๋ง๋๊ธฐ ์ ๊น์ง ๋ชจ๋ public์ด ๋๋ค.
char mName[32] = {};
int mAttack = 0;
int* mArray = nullptr;
private:
int mDefense = 0;
public:
// ํด๋์ค์ ์ผ๋ฐ ๋ฉค๋ฒํจ์(์ผ๋ฐ๋ฉค๋ฒํจ์, ์์ฑ์, ์๋ฉธ์) ๋ด๋ถ์์๋
// this๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
// this๋ ์๊ธฐ ์์ ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์์ด๋ค.
// Player1.Output() ์ด๋ฐ์์ผ๋ก ํด๋์ค์ ๋ฉค๋ฒํจ์๋ฅผ ํธ์ถํ ๋ ๊ฐ์ฒด๋ฅผ
// ์ด์ฉํด์ ํธ์ถํ๊ฒ ๋๋๋ฐ Player1.Output() ์ผ๋ก ํธ์ถํ๋ฉด ํธ์ถํ๋
// ์๊ฐ this๋ Player1์ ์ฃผ์๋ฅผ ๊ฐ์ง๊ฒ ๋๊ณ Player2.Output() ์ผ๋ก
// ํธ์ถํ๋ฉด ํธ์ถํ๋ ์๊ฐ this๋ Player2์ ์ฃผ์๋ฅผ ๊ฐ์ง๊ฒ ๋๋ค.
// ๋ฉค๋ฒํจ์ ๋ด๋ถ์์ ํด๋์ค ๋ฉค๋ฒ๋ณ์๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ์์ this-> ๊ฐ
// ์๋ต๋ ๊ฒ์ด๋ค.
void Output()
{
printf("this = %p\n", this);
printf("๊ณต๊ฒฉ๋ ฅ : %d\n", mAttack);
printf("๋ฐฉ์ด๋ ฅ : %d\n", this->mDefense);
//printf("this Addr = %p\n", &this);
}
void OutputTest()
{
printf("OutputTest Function\n");
}
};
void OutputPlayer(FPlayer* Player)
{
printf("๊ณต๊ฒฉ๋ ฅ : %d\n", Player->Attack);
}
int main()
{
FPlayer Player;
Player.Attack = 10;
OutputPlayer(&Player);
CPlayer Player1, Player2("์ด๋ฆ");
printf("Player1 = %p\n", &Player1);
printf("Player2 = %p\n", &Player2);
// Output ๋ฉค๋ฒํจ์๋ Player1๊ณผ Player2 ๋ชจ๋ ๋์ผํ ์ฃผ์์ ํจ์๋ฅผ
// ์ฌ์ฉํ๊ฒ ๋๋ค. ๊ทธ๋ฐ๋ฐ ๋ฉค๋ฒํจ์์์ ์ ํํ๊ฒ Player1๊ณผ Player2์
// ๋ฉค๋ฒ๋ณ์์ ๊ฐ์ ์ธ์ํ๊ณ ์ฌ์ฉํ ์ ์๋ค.
Player1.mAttack = 100;
Player1.Output();
Player2.mAttack = 300;
Player2.Output();
CPlayer* Player3 = nullptr;
//Player3->Output();
Player3->OutputTest();
printf("Player Size = %d\n", sizeof(CPlayer));
CPlayer copyTest(Player1);
int number = 10;
memset(&number, 1, sizeof(int)); // ๊ฒ๋ ํฐ ๊ฐ ๋์ด.
// memset์ 1๋ฐ์ดํธ ๋จ์๋ก ๊ฐ์ ์ฑ์ฐ๊ฒ ๋จ.
// int๋ 4๋ฐ์ดํธ ์ด๋ฏ๋ก 1๋ฐ์ดํธ ๋จ์๋ก ๊ฐ์ ์ฑ์ฐ๊ฒ ๋๋ฉด
// 0000 0001 0000 0001 0000 0001 0000 0001 ... ์ด๋ ๊ฒ ๋ค์ด๊ฐ๊ฒ ๋์ด์.
// ์์ ๊ฐ์ฒด ์์ฑ. ์ด ์ค์์ ์์ฑ์ ํธ์ถ๋๊ณ , ์ค ๋์ด๊ฐ๊ธฐ ์ง์ ์๋ฉธ์ ํธ์ถ๋๋ฉฐ ์ฌ๋ผ์ง.
CPlayer();
CPlayer* test2 = new CPlayer(Player1);
// std::move : ์ธ์์ ๋ค์ด์จ ๊ฐ์ฒด๋ฅผ ์ด๋์ํค๋ ํจ์.
// CPlayer test2 = std::move(CPlayer()); <- ์ด๋์์ฑ์ ํธ์ถ๋จ
return 0;
}
static, singleton
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
class CStatic
{
CStatic()
{
}
~CStatic()
{
}
private:
// ์ผ๋ฐ ๋ฉค๋ฒ๋ณ์๋ ์์ฑํ๋ ๊ฐ์ฒด๋ง๋ค ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์์ฑํ์ง๋ง,
// static ์ ๊ฒฝ์ฐ, ์ด ํด๋์ค๋ฅผ ์ด์ฉํด์ ์์ฑํ ๋ชจ๋ ๊ฐ์ฒด๊ฐ ๊ณต์ ํ๋ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋๋ค.
// ๋ค๋ง static ๋ฉค๋ฒ '๋ณ์'๋, ํด๋์ค ์ธ๋ถ์ ์ ์ธ ๋ถ๋ถ์ด ํ์ํ๋ค.
int mNumber = 0;
static int mNumberStatic;
public:
int GetNumber() const
{
return mNumber;
}
static void OutputStatic()
{
// mNumber๋ static์ด ์๋. ๋น์ ์ ๋ฉค๋ฒ. ๊ทธ๋์ ์ ์ ํจ์์์ ํธ์ถ ์๋จ.
// ์ ํํ๋, static ๋ฉค๋ฒํจ์์ this๊ฐ ์กด์ฌํ์ง ์์. (๊ทธ์น๊ทธ์น.. ๋ชจ๋ ๊ฐ์ฒด๊ฐ ๊ณต์ ํ๋๊น)
// ๊ทธ๋์ CStatic static1; ํ๊ณ static1->OutputStatic(); ์ด๋, CStatic::OutputStatic(); ์ด๋ ๊ฐ์.
// ๋ค๋ง ํน์ static ๊ฐ์ฒด์ ๋ฉค๋ฒ๋ณ์ ์ถ๋ ฅํ๊ณ ์ถ๋ค๋ฉด - CStatic::OutputObject(&static1); ์ด๋ ๊ฒ.
//printf("Number : %d\n", mNumber);
}
};
// ํด๋์ค์ static ๋ฉค๋ฒ๋ณ์ ์ ์ธ.
int CStatic::mNumberStatic;
class CSingleton
{
public:
CSingleton()
{
}
~CSingleton()
{
}
static CSingleton* GetInstance()
{
if (mInstance == nullptr)
{
mInstance = new CSingleton();
}
return mInstance;
}
static void Destroy()
{
if (mInstance)
{
delete mInstance;
mInstance = nullptr;
}
}
public:
private:
static CSingleton* mInstance;
};
CSingleton* CSingleton::mInstance = nullptr;
int main()
{
CSingleton::GetInstance();
CSingleton::Destroy();
return 0;
}
๋๊ธ๋จ๊ธฐ๊ธฐ