See C + + (class structure, deconstruction) with Assembly vision

Source: Internet
Author: User

Turn from: http://blog.csdn.net/feixiaoxing/article/details/6769663

We discussed the content of basically C language, and haven't really touched on C + + related knowledge. After this blog, we will touch on the content of the class more. Class has a lot of properties, today we are talking about constructors, destructors.

(1) If there is no constructor, destructor.

View Plain class Apple {public:void print () const {return;} };

Although this class doesn't make sense, we find that it still takes up a byte if we use sizeof to calculate the size. So what if there's an Apple variable? To make Apple's variables meaningful, we try to make a difference:

View Plain 66:apple A;   67:a.print ();   00401248 Lea Ecx,[ebp-4] 0040124B call @ILT +0 (Apple::p rint) (00401005) 68:return; 69: We see that the stack allocates four bytes of space to a, which is a byte below the EBP.


(2) When the destructor is invoked.

View Plain class Apple {public:apple () {printf ("Apple ()!\n");}       ~apple () {printf ("~apple ()!\n");} void print () const {return;}

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.