About storage problems in memory for C + + classes

Source: Internet
Author: User

Reference website:

1.http://blog.csdn.net/fuzhongmin05/article/details/59112081

2.http://www.cnblogs.com/jerry19880126/p/3616999.html

Website 1 divides c + + memory into four zones: Global data area, code area, stack area, heap area.

Global variables, static variables, constants are placed in the global data area, member functions and non-member functions are placed in the code area, function parameters, local variables, return values are placed in the stack area, and the rest is placed in the heap area.

Inside the content there is a section of code run does not pass, the code is as follows:

1#include <iostream>2 using namespacestd;3 classD4 {5  Public:6     voidPrintA ()7     {8cout <<"PrintA"<<Endl;9     }Ten     Virtual voidPRINTB () One     { Acout <<"PRINTB"<<Endl; -     } - }; the intMainvoid) - { -D *d =NULL; -D->PrintA (); +D->printb (); -     return 0; +}

Site 1 does not explain why the program crashed.

Reference Site 2 illustrates the reason that when a class has virtual functions, there are hidden virtual pointers and virtual tables in the class. Virtual pointers are created in the constructor function.

Above is my understanding, there are mistakes in the place I hope you correct me.

About storage problems in memory for C + + classes

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.