Advertisement
kalabukdima

Untitled

Nov 17th, 2020
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <class T>
  5. class Singleton {
  6. public:
  7.   static T& GetInstance() {
  8.     static T instance_;
  9.     return instance_;
  10.   }
  11.  
  12. protected:
  13.   Singleton() {}
  14. };
  15.  
  16. class Foo : public Singleton<Foo> {
  17. public:
  18.   std::vector<int> value;
  19. };
  20.  
  21. int main() {
  22.   Foo::GetInstance().value.push_back(1);
  23.   std::cout << Foo::GetInstance().value.size() << "\n";
  24.   std::cout << "Hello\n";
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement