您的位置:首页 > Web前端

剑指offer第2题 单件模式

2013-05-10 17:48 155 查看
#include <iostream>

using namespace std;

class Singleton
{
public:

static Singleton& getInstance()
{
static Singleton dp;
return dp;
}

void message()
{
cout<<"Singleton Message"<<endl;
}
private:
Singleton()
{
cout<<"construct Singleton!"<<endl;
}
};

int main(int argc, char* *argv)
{
Singleton::getInstance().message();
Singleton::getInstance().message();
Singleton::getInstance().message();
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: