C ++静态数据成员初始化
1)是否确实总是在调用main()之前初始化类的静态数据成员?
1) Is it true that static data members of classes always get initialized before main() called?
2)如果类初始化代码的静态数据成员使用其他转换单元的全局静态变量,是否可能发生静态初始化顺序惨败"?
2) Is it true that "static initialization order fiasco" can happen if static data member of class initialization code uses global static variable of other translation unit?
我在哪里可以了解更多信息?在2003年的C ++标准中找不到答案.
Where can I read more about it? I couldn't find answer in 2003 standard of C++.
非常感谢.
1)是否确实总是在调用main()之前初始化类的静态数据成员?
1) Is it true that static data members of classes always get initialized before main() called?
是的,它们总是在程序开始执行之前被初始化.
yes they would always be initialized before program starts executing.
2)如果类初始化代码的静态数据成员使用其他转换单元的全局静态变量,是否可能发生静态初始化顺序惨败"?
2) Is it true that "static initialization order fiasco" can happen if static data member of class initialization code uses global static variable of other translation unit?
是的,与此同时,在main()
执行之前初始化的所有其他事情也会发生.
Yes, along with this it also happens for every other thing which is initialized before main()
execution.