防止静态初始化顺序“fiasco”,C ++ [英] Prevent static initialization order "fiasco", C++

查看:296
本文介绍了防止静态初始化顺序“fiasco”,C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我阅读了一个真棒的C ++常见问题(这是真的很好! https://isocpp.org/faq )和阅读主题关于如何防止静态初始化顺序fiasco。因此,作者建议将静态变量包装到函数中,从而通过维护变量的创建顺序来防止fiasco。但在我看来这是一个粗鲁的解决方法。所以我的问题是,是否有任何现代的,更多的模式导向的方式来防止这种失败,但将静态东西包装函数?

Once I was reading an awesome C++ FAQ (It is really good!! https://isocpp.org/faq) and read the topic about how to prevent the static initialization order "fiasco". So the author advises to wrap the static variables into functions, thus to prevent the "fiasco" by maintaining the creation order of variables. But this seems to me a rude workaround. So my question is, is there any modern, more pattern oriented way to prevent this "fiasco" but to wrap the "static stuff" into functions???

推荐答案

现代的,更多的面向模式的方法是首先不使用全局变量<

没有其他方法。

的失败,否则!

这篇关于防止静态初始化顺序“fiasco”,C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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