-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathSingleton.cpp
More file actions
37 lines (35 loc) · 880 Bytes
/
Singleton.cpp
File metadata and controls
37 lines (35 loc) · 880 Bytes
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
class Singleton
{
public:
static Singleton& instance()
{
// 객체를 사용할때까지 초기화를 미룬다.
if (instance_ == nullptr)
{
instance_ = new Singleton();
}
return *instance_;
}
Singleton(Singleton const&) = delete;
Singleton& operator=(Singleton const&) = delete;
Singleton(Singleton&&) = delete;
Singleton& operator=(Singleton&&) = delete;
private:
Singleton() = default;
static Singleton* instance_;
};
class Singleton
{
public:
static Singleton& instance()
{
static Singleton* instance = new Singleton();
return *instance;
}
Singleton(Singleton const&) = delete;
Singleton& operator=(Singleton const&) = delete;
Singleton(Singleton&&) = delete;
Singleton& operator=(Singleton&&) = delete;
private:
Singleton() = default;
};