//the object management model of the class#include<iostream>using namespacestd;classpointa{Private: intX//occupies 4 byte-sized memory space intY//occupies 4 byte-sized memory space intZ//occupies 4 byte-sized memory space};//occupies 12 bytes in totalclasspointb{ Public: Pointb (int_x,int_y,int_z) {x=_x; Y=_y; Z=_z; } voidGetX () {cout<< x<<Endl;; } voidGetY () {cout<< y <<Endl;; }Private: intx; inty; intZ; Static intc;};voidProtecta () {cout<<"The size of the Pointa in memory is"<<sizeof(Pointa) <<"of bytes"<< Endl;//Print 12 bytescout <<"The size of the pointb in memory is"<<sizeof(POINTB) <<"of bytes"<< Endl;//Print 12 bytes//Run result indicates static member variable of class, member function does not occupy memory space in class//In essence, the C + + compiler stores the static member variables of member variable member functions in class objects separately//non-static member variables: stored in an object, with the same memory layout and byte alignment as the struct variable//static member variables: stored in the global zone//member functions (including static member functions): stored in code area//C + + compiler internal processing of ordinary member functions see Figure 1//classes in C + + are actually composed of structs (stored data) + global functions in the C language .//The C + + compiler makes special handling of functions in the class, and each function implicitly passes an object pointer (essentially a struct pointer) .//is through this object pointer C + + compiler to find the member properties in each object//for static member functions, the C + + compiler does not pass an object pointer to this function because the static member function belongs to the class}/*Summary: 1. member variables and member functions in C + + class objects are stored separately. Memory four-zone model in C language still works! 2. The normal member function of a class in C + + implicitly contains a pointer to the current object. 3. Static member function, static member variable belongs to class static member function differs from ordinary member function static member functions do not contain pointers to specific objects ordinary member functions contain a pointer to a specific object*/voidMain () {protecta (); System ("Pause");}
The object management model of C + + class