标签:sid function problem art list initial ram with func
Effective C++ Scott Meyers
Chapter 1. Uses and Abuses of vector
1. Item 4: Make sure that objects are initialized before they‘re used.
Use member initialization list to initialize the member.
Sometimes, the initialization list must be used, even for built-in types. For example, data members that are const or are references must be initialized.
Always list members in the initialization list in the same order as they‘re declared in the class.
When class has multiple constructors, omit the entries in the list for data members where assignment works as well as true initialization, moving the assignments to a single function that all the constructors call.
Static objects declared inside functions are known as local static objects, and the other kinds of static objects are known as non-local static objects.
The relative order of initialization of non-local static objects defined in different translation units is undefined.
Define the non-local static objects in local functions, where it‘s declared static. These functions return references to the objects they contain. (Singleton Pattern)
The functions contain static objects makes them problematic in multithreaded systems. One way to deal with it is to manually invoke all the reference-returning functions during the single-threaded startup portion of the program. This eliminates initialization-related race conditions.
标签:sid function problem art list initial ram with func
原文地址:https://www.cnblogs.com/lefthook/p/10167913.html