Can I safely store things in a vector in non-pod static data element constructor constructors? Example:
class Foo { public: static Foo& instance() { static Foo inst; return inst; } void store(int x) { numbers.push_back(x); } private: Foo() {} std::vector<int> numbers; }; class Bar { public: Bar() { Foo::instance().store(5); } }; class Thing { public: static Bar bar; }; // in thing.cpp: Bar Thing::bar;
Is the above code correct and produces specific behavior?
Note. The question is not about static locales, but about std::vectordepending on any static initialization that may not occur before the bar constructor.
std::vector
std::vector does not use any static data, therefore it is safe.
, std::vector, , (, ), , .
std::vector freestore (aka heap), , , std::vector, , main.
main
. , .
:
Source: https://habr.com/ru/post/1530303/More articles:How to identify / verify FaceTime contact information? - iosThe character "f" is considered true in ng-show - angularjsIs there any way to show output during database update? - c #PostgreSQL query dividing by zero error - sqlHow to set up a legend with a certain height in highstock? - jqueryhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1530304/restrict-access-to-the-admin-url-by-ip-in-django-with-nginx-and-gunicorn&usg=ALkJrhh3zppCo4QsgUMHWmHwnFGHS9ixJgnuget pack [someProject.csproj] won't let me change the title or description - nugetWhy not ALAssetLibrary -enumerateGroupsWithTypes: usingBlock: "stop" when I say? - iosASP.NET MVC 4 Session Timeout - asp.net-mvc-4How to get multiple parameters with the same name from a URL in JavaScript - javascriptAll Articles