Advertisement
CruelSysOP

C++ Singleton

Nov 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. // Singleton.h
  2. class Singleton
  3. {
  4.   private:
  5.     static Singleton * p_instance;
  6.     // Конструкторы и оператор присваивания недоступны клиентам
  7.     Singleton() {}
  8.     Singleton( const Singleton& );  
  9.     Singleton& operator=( Singleton& );
  10.   public:
  11.     static Singleton * getInstance() {
  12.         if(!p_instance)          
  13.             p_instance = new Singleton();
  14.         return p_instance;
  15.     }
  16. };
  17.  
  18. // Singleton.cpp
  19. #include "Singleton.h"
  20.  
  21. Singleton* Singleton::p_instance = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement