singleton model

class Singleton
{
private:
    static Singleton s;
    int i;
    Singleton(int i)
    {
        this->i = i;
    }
    void operator= (Singleton s)
    {
        s.i = this->i;
    }
    Singleton(Singleton & s)
    {
        this->i = s.i;
    }
public:
    static Singleton & getHandle()
    {
        return s;
    }
    void setValue(int i)
    {
        this->i = i;
    }
    int getValue()
    {
        return i;
    }
};

Singleton Singleton::s(50);

int main() 

    Singleton &s = Singleton::getHandle();
    printf("%d\n",s.getValue());
    
    system("pause");
    return 0;
}

posted on 2012-08-24 07:27 三少_爷 阅读(128) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿

随笔分类

随笔档案

My Website

搜索

最新评论

阅读排行榜

评论排行榜