See C + + (copy, assignment function) with Assembly vision

Source: Internet
Author: User

Turn from:

Copy constructors and copy functions are two of the more important functions within a class. What is the difference between the two? In fact, it is also very simple, for example, to add the definition of a class:

View Plain class Apple {public:apple () {printf ("Apple ()!\n");}       Apple (apple& a) {printf ("Copy apple ()!\n");}       apple& operator= (apple& a) {printf ("= apple () \ n"); return *this;}       ~apple () {printf ("~apple ()!\n");}   void print () const {return;} };

So what are the functions that we call when we call them in the following function?

View Plain void process ()    {       apple a, c;        apple b =a;       c = b;   }        In fact, the results of the compilation is such that we can take a look at it and try to read it ourselves. If you don't understand it at once, you can read it more times.

View Plain 70:       apple a, c;   0040127D    lea         ecx,[ebp-10h]   00401280    call         @ILT +70 (apple::apple)   (0040104b)    00401285   MOV         DWORD PTR [EBP-4] ,0   0040128c   lea         ecx,[ebp-14h]    0040128f   call         @ILT +70 (apple::apple )   (0040104b)   

Related Article

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: 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.