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