Static variables initialisation order

后端 未结 7 1205
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 15:20

C++ guarantees that variables in a compilation unit (.cpp file) are initialised in order of declaration. For number of compilation units this rule works for each one separat

7条回答
  •  不知归路
    2020-11-22 15:52

    If you really want to know the final order I would recommend you to create a class whose constructor logs the current timestamp and create several static instances of the class in each of your cpp files so that you could know the final order of initialization. Make sure to put some little time consuming operation in the constructor just so you don't get the same time stamp for each file.

提交回复
热议问题