Eeer in silence
Original address:
Http://www.cnblogs.com/hebaichuanyeah/p/5608209.html
A singleton pattern is a guarantee of a class that has only one instance and provides global access to that instance.
1. The non-reliable single case mode
It is easy to write the following code, using the static function in the Singleton class to get the unique static pointer variable, while the constructor of the Singalton class is set to private, and no multiple objects are allowed to be constructed.
#include "iostream" using namespace Std;class singleton{private: Singleton () {} static Singleton *singleobject ;p ublic: Static Singleton * Getsingleobject () { if (singleobject==null) { singleobject = new Singleton (); } return singleobject;} ; Singleton * Singleton::singleobject;main () { Singleton * p= singleton::getsingleobject ();}
[design mode]<3>. C + + and Singleton mode (singleton pattern)