单例模式

单例模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class  {
public:
cSingle(const cSingle&) = delete;
cSingle& operator = (const cSingle&) =delete;

static cSingle* instance() {
static cSingle __instance;
return &__instance;
}
private:
cSingle() {};
};
int main(){
cSingle* first = cSingle::instance();
cSingle* second = cSingle::instance();
cout << "the first address is :" << first << endl;
cout << "the second address is :" << second << endl;
}