C++单例

template<typename T>
class Singleton {
public:
    static T& GetInstance() {
        static T instance;
        return instance;
    }

    virtual ~Singleton() {
    }

    Singleton(const Singleton&) = delete;
    Singleton& operator =(const Singleton&) = delete;

protected:
    Singleton() {
    }
};

用法

class Config : public Singleton<Config>
{
    friend class Singleton<Config>;
public:
    Config();
    ~Config();
};

  

 

posted @ 2024-04-16 08:51  快雪  阅读(1)  评论(0编辑  收藏  举报