游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1476|回复: 0

设计模式---单件(C++版) 希望大家顶一下

[复制链接]

4

主题

7

帖子

7

积分

新手上路

Rank: 1

积分
7
发表于 2010-8-30 14:53:00 | 显示全部楼层 |阅读模式
//代码比较简单,见笑了
#include "iostream"
using namespace std;
class CSingleton
...{
public:
    static CSingleton* Instance();
protecd:
    CSingleton()...{};
private:
    static CSingleton* _Instance;

};
CSingleton* CSingleton::_Instance = 0;
CSingleton* CSingleton::Instance()
...{
if(_Instance == 0)
...{
    return new CSingleton();
}
return _Instance;
        
}
int main()
...{
    CSingleton *t = CSingleton::Instance();
    return 0;
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-7 04:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表