In the book "C ++ language", the author has claimed
ever Sometimes, when you design a library, it is necessary, or simply convenient, invent with the sole purpose and cleanliness for a beginner with a manufacturer and a destroyer. Such type will be used only once: to allocate a fixed object so that the constructor and the district will be called.
I am interested in what reference is this statement mentioning? Or how does this statement help in software design?
In the book also gives examples
class Zlib_init {Zlib_init (); ~ Zlib_init (); }; Class Zlib {Fixed Zlib_init x; }
And the book explains that
Unfortunately, it is not guaranteed that such an object is initialized before its earlier use and It is destroyed after its last use.
Why can this happen?
Thanks for the clarification.
The C ++ standard does not specify the order in which static objects are created. Therefore, if you need some hierarchy in the stationary object, then you need to rely on the other (eg, one should be a member of the other). Construction from the book guarantees this behavior. For example, a fictional game engine requires a sound and graphics engine, if you declare them as stable objects in separate compilation units, and use one from the other, then
See the entry for the second part of your question.
Comments
Post a Comment