Template C++ de Singleton con auto_ptr
?Ver código CPP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #if !defined(__SINGLETON_AUTO_PTR__) #define __SINGLETON_AUTO_PTR__ #include <memory> #include "uncopyable.h" template <typename T> class Singleton : public uncopyable { public: static T* getInstance(){ static const std::auto_ptr<T> __instance(new T); return __instance.get(); } protected: Singleton(){}; virtual ~Singleton(){}; }; #endif |
?Ver código CPP
1 2 3 4 5 6 7 8 9 10 11 12 | #ifndef UNCOPYABLE_H_ #define UNCOPYABLE_H_ class uncopyable{ // Idea from Effictive C++ by Scott Meyers protected: uncopyable() {} ~uncopyable() {} private: uncopyable(const uncopyable &); uncopyable & operator=(const uncopyable &); }; #endif |
| Imprimir artículo | Este artículo fue publicado por brue el octubre 11, 2010 a las 05:24, y está archivado en C++, Programación. Sigue las respuestas a esta entrada a través de RSS 2.0. Puedes dejar un comentario o enviar un trackback desde tu propio sitio. |
![[bRue.org] [bRue.org]](http://www.brue.org/wp-content/uploads/logo_bw.png)