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 ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.