See C + + (such as static variables, static functions) with Assembly vision

Source: Internet
Author: User

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  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.