其他分享
首页 > 其他分享> > 类的编译顺序

类的编译顺序

作者:互联网

Initialization order

The order of member initializers in the list is irrelevant: the actual order of initialization is as follows:

1) If the constructor is for the most-derived class, virtual bases are initialized in the order in which they appear in depth-first left-to-right traversal of the base class declarations (left-to-right refers to the appearance in base-specifier lists) 2) Then, direct bases are initialized in left-to-right order as they appear in this class's base-specifier list 3) Then, non-static data member are initialized in order of declaration in the class definition. 4) Finally, the body of the constructor is executed

(Note: if initialization order was controlled by the appearance in the member initializer lists of different constructors, then the destructor wouldn't be able to ensure that the order of destruction is the reverse of the order of construction)

标签:顺序,class,member,编译,right,base,initialized,order
来源: https://www.cnblogs.com/wildricky/p/14833229.html