Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // c1.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. class Singleton {
  9. static Singleton* instance;
  10. int data;
  11.  
  12. // Private constructor so that no objects can be created.
  13. Singleton() {}
  14.  
  15. public:
  16. static Singleton* getInstance() {
  17. if (!instance) {
  18. instance = new Singleton;
  19. cout << "new class" << endl;
  20. }
  21. return instance;
  22. }
  23.  
  24.  
  25. };
  26.  
  27. //Initialize pointer to zero so that it can be initialized in first call to getInstance
  28. Singleton* Singleton::instance = 0;
  29.  
  30. int main() {
  31.  
  32. Singleton* s = Singleton::getInstance();
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement