Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. //
  2. #define declare_singleton(class)    \  
  3. private:                \
  4. class();                \
  5. class(const class&);            \
  6. class(class&);              \
  7. void operator=(const class&);       \   //usw  
  8. ~class();               \
  9. public:                 \
  10. friend class &singleton<class>();  
  11.  
  12. //
  13. #define define_singleton(class)     \  
  14. template <typename T>           \
  15. T &fSingleton(){            \
  16.     static T t;             \
  17.     return t;               \
  18. }                   \
  19. class &S_##class=fSingleton<class>();  
  20.  
  21. //x.h
  22. extern class x{
  23.     declare_singleton(x);
  24. } &S_x;
  25.  
  26. //x.cpp
  27. define_singleton(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement