Deep exploration of C ++ object models Chapter 5 construction, deconstruction, copy semantics

zhaozj2021-02-16  63

5.2 Object Construction under Inherited System The expansion operation made by the compiler is approximately as follows: 1. Record the Data Members initialized in the initializataion list. . 2, if there is a MEMBER that does not appear in the Member Initialization List, but he is another default constructor, then the default constructor must be called 3, before this, if the class object has Virtual Table Pointers, then they must be set Disposal to point to appropriate vTable4, before that, all the base class constructors of all the previous layers must be called, in order to declaration in Base Class, a) If the base class is listed in the Member Initialization List, then any clear The formulated parameters are passed in the past b) If the base class is not listed in the Member Initialization List, it has Default Constructor, then DEFAULT CONSTRUCOTR C) If the base class is the second or subsequent BASE of multiple inheritance Class, then the THIS pointer must be adjusted. 5. Before that, all Virtual Base Class Constructors must be called, from the deepest to the most. a) If the class is listed in the Member Initialization List, then any clearly developed parameters are passed, if the class is not listed in the Member Initialization List, and it has default constructor, then the default construcotr B) is called. The convenient amount of each Virtual Base Class Subject in the Class must be accessed during execution c) If Class Object is the bottom Class, its constructors may be called, and some mechanisms that support this behavior must be put in. ! Initialization Time of VPTR: After the base class construcotrs call operation, but before the programmer's Member Initialization List is called. So call the Class's virtual function in the MEMBER INITIZATION LIST of Class, but it is not necessarily meaningful. Because its Data MEMBER has not been initialized! Hey! Virtual Inheritance: Virtual Base Class only needs to be initialized once. Add a auxiliary variable to determine only once!

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

New Post(0)