1 #include <iostream>
2 #include <string>
3 #include "Singleton.h"
4
5 using namespace std;
6
7 class SObject
8 {
9 friend class Singleton<SObject>; // 当前类需要使用单例模式
10
11 SObject(const SObject&);
12 SObject& operator= (const SObject&);
13
14 SObject()
15 {
16 }
17 public:
18
19 void print()
20 {
21 cout << "this = " << this << endl;
22 }
23 };
24
25 int main()
26 {
27 SObject* s = Singleton<SObject>::GetInstance();
28 SObject* s1 = Singleton<SObject>::GetInstance();
29 SObject* s2 = Singleton<SObject>::GetInstance();
30
31 s->print(); // 0x9621008;
32 s1->print(); // 0x9621008;
33 s2->print(); // 0x9621008;
34
35 return 0;
36 }