Deep Explore C ++ Object Model Chapter 3 Data Language

zhaozj2021-02-16  52

C Standard does not enhance the "Base Class Sunjects" "Different Access Layers Remember Data Members], which does not specify" Virtual Funcitons and Virtual Base Class "implementation details.

3.1 Layout of Data Member C Standard Requirements: MEMBERs in the same access section are arranged in order, and between them are not necessarily. The storage location of VPTR is not necessarily, and the compiler is specified by itself.

3.3 Data MEMBER Access Static Data Member: As long as you are static member, then access is a fixed time because he is equivalent to a global variable. If you go to a Static Data MEMBER, you will get a pointer to its data type, not a pointer to its Class Member. Because Static Member is not included in a Class Object. Since Static Member is placed in Global Data Segment, you need to naming him to prevent conflicts! NonStatic Data Member: Access to a NonStatic Data MEMBER, the compiler needs to add the Class Object's hand address to the offset in the object in the object. Origin._x -----> & Origin (& Point3D :: X-1); if the Data Member belongs to a base class subjects, it is the same because its offset two will be obtained during compilation. Musical inheritance: "Access Class MEMBERS via Baseclass Subject" adds a new layer of indirectibility. If it is an object to access the base class, the same time is the same, because its offset is fixed during the compilation period, and if there is a pointer to access, it will be complicated because it does not know the pointer is What type of point pointing! May be Base Class, or a derived class, an additional indirect reference can be resolved.

3.4 "Inheritance" and Data Memberc , a Derived Class Object's space is your own MEMBERS BASE CLASS MEMBERS! And the order in which C Standard is also forced. When virtual inheritance: Access to the Virtual Base Class, you need to pass a pointer to the base class to access, rather than before the calculated offset is based on the calculated offset as before. Therefore, virtual inheritance is very poor! It's doubled! Pointer to MEMBERS:

转载请注明原文地址:https://www.9cbs.com/read-24322.html

New Post(0)