fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T>
  5. class Singleton
  6. {
  7. public:
  8. static T& Get() noexcept
  9. {
  10. static T instance;
  11. return instance;
  12. };
  13.  
  14. protected:
  15. Singleton() = default;
  16. };
  17.  
  18. class Foo : public Singleton<Foo>
  19. {
  20. public:
  21. int t = 0;
  22. };
  23.  
  24. int main() {
  25.  
  26. Foo foo;
  27. Foo::Get().t += 10;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 4836KB
stdin
Standard input is empty
stdout
Standard output is empty