关于本章
需要考虑的问题:
- 唯一性
- race condition
Static-Initialization-Order-Fiasco 和 它的解决方案
在 Static-Initialization-Order-Fiasco
中,描述了它;下面对它的解决方案进行汇总:
How to prevent
1、construct on first use,参见 Construct-On-First-Use-Idiom
章节
2、singleton,参见Singleton
3、Nifty counter idiom
Idioms
name | 描述章节 | 参见 |
---|---|---|
Attach-by-Initialization | - C++\Idiom\OOP\Attach-by-Initialization |
|
Construct-On-First-Use | - Construct-On-First-Use-idiom |
- stackoverflow Construct on first use + forced initialization to solve static initialization order fiasco? - parashift Construct on first use |
Runtime Static Initialization Order Idioms | - More C++ Idioms/Runtime Static Initialization Order Idioms | |
Nifty counter idiom | - Nifty-Counter-idiom |
- More C++ Idioms/Nifty counter idiom |
Pattern
Singleton: 参见C++\Pattern\Singleton
CppCoreGuidelines I.22: Avoid complex initialization of global objects
TODO
在下面章节中,提及了static variable的initialization问题:
cppreference Default initialization