-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsingleton1.cpp
More file actions
44 lines (35 loc) · 742 Bytes
/
singleton1.cpp
File metadata and controls
44 lines (35 loc) · 742 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
38
39
40
41
42
43
#include <iostream>
using namespace std;
class singleton{
public:
static singleton * getInstance();
private:
singleton();
singleton(const singleton&);
singleton& operator=(const singleton&);
static singleton * instance;
};
singleton::singleton()
{
}
singleton::singleton(const singleton&)
{
}
singleton& singleton::operator=(const singleton&)
{
}
///////////////////////////////////////////////////
singleton * singleton::instance = new singleton();
singleton * singleton::getInstance()
{
return instance;
}
int main() {
singleton * pInstance1 = singleton::getInstance();
singleton * pInstance2 = singleton::getInstance();
if(pInstance1 == pInstance2)
{
cout << "Good singleton example!\n";
}
return 0;
}