fork download
  1. #include <stdio.h>
  2.  
  3. template<typename T>
  4. class singleton {
  5. static T* g_pInstance;
  6. public:
  7. static T* getInstance() {
  8. return g_pInstance;
  9. }
  10. singleton() {
  11. g_pInstance = (T*)this;
  12. }
  13. ~singleton() {
  14. if(g_pInstance == this) g_pInstance = nullptr;
  15. }
  16. };
  17.  
  18. template<typename T>
  19. T* singleton<T>::g_pInstance = nullptr;
  20.  
  21. class Any : public singleton<Any> { /* Done */ };
  22.  
  23. int main() {
  24. printf("0x%x\n", Any::getInstance());
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
0x0