C ++静态数据成员初始化 [英] C++ static data members initialization

查看:169
本文介绍了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.

这篇关于C ++静态数据成员初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆