Non-static member variables, two possible, either class-custom, or inherited. Based on the "Deep Exploration of C + + object Model" interpretation.
class x{ private: int x, Y, z;};
In this class, there are three private member variables (whether private, protected, or public) that are arranged in a certain order ( generally based on the order of the definitions ), and the only thing to note is that some variables need to be aligned to fill. The order in memory is: x, Y, Z;
If you need to operate on these three variables, you will actually populate the member function with a pointer , referring to "easy to use MFC".
class x{ public: void f ()/* filled here, get: void f ((x*) this)* / { x+ +; /* equivalent to this->x++; */ } private: int x, Y, z;};
So, how do you get the address of the member variable x? Uses: Object first address +offset (x), that is, the first address + Member variable offset, the composition gets the address of the member variable.
The second case: a member variable that has been inherited. In the same form, the inherited member variable is added to the memory block of the member variable of the object, and the order problem occurs. The answer to the book is: In general, the inheritance is in the front, the derived class is in the back ( this is verified by the program ).
C + + object model: member variables < one > non-static Members