Turn from: http://blog.csdn.net/feixiaoxing/article/details/6783482
Friends who have seen the design pattern know that we can not do without the static function of the class when we design the single piece mode. Unlike the member variables of a class, the static variables of a class belong to all class object data, and the static functions of a class are owned by all class functions, unlike the member functions of a class. This sentence read to think of a bit of a mouthful, but it does not matter, we can use a piece of code to explain the problem.
(1) Static variables
As usual, we start with a preliminary definition of the class, as follows:
View Plain class Employee {Public:employee () {} ~employee () {} static int value; }; So, the value that appears here is shared, and we can look at the relevant function code:
View Plain 67: int employee::value = 0; 68: 69: void process () 70: { 00401240 push ebp 00401241 mov ebp,esp 00401243 push 0FFh 00401245 push offset __ehhandler$?process@ @YAXXZ (0041f469) 0040124a mov eax,fs:[00000000] 00401250 push eax 00401251 mov dword ptr fs:[0],esp 00401258 sub esp,48h 0040125b push ebx