Using static and global objects

A static variable in a global function will be created at some point before the function is first called. Similarly, a static object that is a member of a class will be initialized at some point before it is first accessed.

Static and global objects are constructed before the main function is called, and destroyed after the main function finishes. The order of this initialization has some issues. The C++ standard says that the initialization of static and global objects defined in a source file will occur before any function or object defined in that source file is used, and if there are several global objects in a source file, they will be initialized in the order that they are defined. The issue is if you have several source files with static objects in each. There is no guarantee on the order in which these objects will be initialized. It becomes a problem if one static object depends on another static object because you cannot guarantee that the dependent object will be created after the object it depends upon.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset