The constructors of globally declared classes are invoked before main is entered. While this can be confusing to a new reader of the code because it is done so infrequently, is it necessarily a bad idea?
The constructors of globally declared classes are invoked before main is entered. While this
Share
It’s not necessarily a bad idea, but usually, yes.
First, it’s global data, and globals are usually a bad thing.
The more global state you have, the harder it becomes to reason about your program.
Second, C++ doesn’t guarantee intialization order of static objects defined in different translation units (.cpp files) — so if they depend on one another, you might be in trouble.