// Singleton.h
class Singleton
{
private:
    Singleton() {}
    ~Singleton() {}
    Singleton(Singleton const &other);
    Singleton &operator=(Singleton const &other);
public:
    static Singleton &Instance() { return ms_singleton; }

    static Singleton ms_singleton;
};

// Singleton.cpp
// PUT IT in ".cpp" file.
Singleton Singleton::ms_singleton;

int main(int argc, char *argv[])
{
    Singleton &s1 = Singleton::Instance(),
              &s2 = Singleton::Instance();

    cout <<&s1 <<" : " <<&s2 <<endl;

    return 0;
}

Design Pattern --- Singleton

相关文章:

  • 2021-07-27
  • 2021-07-07
  • 2021-09-19
  • 2021-12-25
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-30
  • 2021-09-24
  • 2021-10-16
  • 2021-11-10
  • 2021-08-05
  • 2021-10-08
相关资源
相似解决方案