单例模式

#include <iostream>

class Singleton {
public:
    Singleton(const Singleton&) = delete;
    Singleton& operator = (const Singleton&) = delete;
    static Singleton& get_instance() {
        static Singleton instance;
        return instance;
    }
    void show() { std::cout << "In Singleton show()." << std::endl; }
private:
    Singleton() {}
};

int main(int argc, char *argv[]) {
    Singleton& instance = Singleton::get_instance();
    instance.show();
    return 1;
}

  

posted @ 2022-02-25 17:47  南乡水  阅读(3)  评论(0编辑  收藏  举报