Posted By

Bloomy on 03/30/10


Tagged

design-pattern


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


application_singleton_h


 / Published in: C++
 

  1. //------------ APPLICATION.H
  2.  
  3. #ifndef APPLICATION_H
  4. #define APPLICATION_H
  5.  
  6. class Application
  7. {
  8. public:
  9. Application();
  10. static Application *getInstance();
  11. private:
  12. static Application *_application;
  13. };
  14.  
  15. #endif // APPLICATION_H
  16.  
  17.  
  18. //------------ APPLICATION.CPP
  19.  
  20. #include "application.h"
  21.  
  22. // Inicializacion de los atributos estaticos
  23. Application *Application::_application = 0;
  24.  
  25. Application::Application()
  26. {
  27. if(_application == this) {
  28. _application = 0;
  29. }
  30. }
  31.  
  32. Application *Application::getInstance()
  33. {
  34. if(!_application) {
  35. _application = new Application();
  36. }
  37. return _application;
  38. }

Report this snippet  

You need to login to post a comment.