Member fields, order of construction

前端 未结 2 1398
[愿得一人]
[愿得一人] 2020-11-30 10:49

In C++, when doing something like what you see below, is the order of construction guaranteed?

Logger::Logger()
    : kFilePath_(\"../logs/runtime.log\"), lo         


        
2条回答
  •  无人及你
    2020-11-30 11:13

    The order of construction is the order of declaration in the class definition.

    If the ordering in the ctor-initializer differs, this does not affect the order of construction. Your compiler may warn on this.

    See 12.6.2/5 (2003 wording, named [class.base.init]):

    nonstatic data members shall be initialized in the order they were declared in the class definition (again regardless of the order of the mem-initializers).

提交回复
热议问题