1. The size of an empty class is 1 byte. This is to allow two objects of this class to be configured with a unique address in memory.
2. nonstatic data member is placing a "individual class object" of interest, and the static data members place the "entire class" of interest.
3. The C + + object model places nonstatic data members directly in each Classs object. The same is true for inherited nonstatic data members, either virtual or nonvirtual base class. However, there is no forced definition of the order in which they are arranged. As for the static data members, it is placed in the program's global data segment, which does not affect the size of individual class object. Under the program, no matter how many objects (derived directly or indirectly) the class is generated, the static data members will always have only one copy of the instance (even if the class, without any object instance, its static data Members also exist).
4. nonstatic data members are arranged in class object in the same order as they are declared, and any static data member intervening in the middle will not be placed in the object layout. Because static data members are placed in data segment, it is independent of the individual class object.
Access to Data member
1. If there are two classes, they declare a static member of the same name, then when they are placed in the program's data segment, it causes a name conflict. The solution for the compiler is to encode each static data member for a unique identification code.
2. nonstatic data members are stored directly in each class object. Unless explicit or implicit class object is passed, there is no way to access them directly. As long as the programmer processes a nonstatic data member directly in a member function. The so-called implicit is going to happen. For example, the following code:
Point3D point3d::translate (const Point3D &PT) { + = pt.x ; + = Pt.y ; + = pt.z;}
The apparent view of direct access to X, Y, Z is actually done by a "implicit class object" (expressed by this pointer). In fact, the parameters of this function are:
Point3D point3d::translate (Point3D *constThisconst Point3D &PT) { this->x + = pt.x ; this->y + = pt.y ; this->z + = pt.z;}
To access an NONSTAIC data member, the compiler needs to add the starting address of class object to the offset of the data member. As an example, if:
0.0;
Then the address &origin._y will be equal to:
1);
Note the-1 operation. A pointer to data member, whose offset value is always added to 1, allows the compilation system to differentiate "a pointer to data member to indicate the first member of class and a pointer to the data member, No member "two cases were noted.
"C + +" deep Explore C + + object Model reading notes--data semantics (the Semantics of data)