64,683
社区成员
发帖
与我相关
我的任务
分享
// ThinkingInCpp.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Singleton
{
private:
static Singleton s;
int i;
Singleton(int x):i(x){}
void operator=(Singleton &s){s.i = this->i;};
Singleton(Singleton &s){this->i = s.i;}
public:
static Singleton & getHandle()
{
return s;
}
int getValue()
{
return i;
}
void setValue(int x)
{
i = x;
}
};
Singleton Singleton::s(50); //发生了什么,有没有s对象
int _tmain(int argc, _TCHAR* argv[])
{
Singleton & s = Singleton::getHandle (); //发生了什么。
cout<<s.getValue()<<endl;
system("pause");
return 0;
}