C++ Segmentation Fault when using cout in static variable initialization

后端 未结 3 1731
攒了一身酷
攒了一身酷 2021-02-19 16:57

I have a program where I use cout to emit debug information. The code is executed in the initialization of a static global variable, i.e. quite early in the program execution. W

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 17:46

    Static variable initialization is a no-man's-land. You will avoid problems if you avoid doing significant work there. Maybe you should wrap the static variable in a Singleton pattern so you can defer initialization to the first time it's used.

提交回复
热议问题