qt 类单例模式

有时候类不需要重复新建(new),只需要新建一个实例,用的时候拿过来直接使用

class xx 
{
    public;
    static xx *getInstance();
}


/****************   单例模式        ***************/
xx *xx::getInstance()
{
    if(NULL == instance)
    {
        instance = new xx();
    }

    return instance;
}

 

posted @ 2020-08-12 12:11  icyvalley  阅读(296)  评论(0)    收藏  举报