Starting and ending a C ++ program is a gray area because it is not clear how much of your code you are already using (because it has been initialized) and how much has not yet begun. When shutting down, the same thing happens for the destructor ... it is not clear how many subsystems are already disabled when your static instances are destroyed.
Also, you should never use static initialization for anything that might fail, debugging before or after main
can be very complicated.
Note also that the order in which the statics are initialized is not defined (except for relatively different statistics in the same compilation unit), and it can change from one compilation to the next. This means that you can be satisfied with the work program until, for some strange reason, you get a different initialization order and everything stops working without any code changes.
Using static initialization for extremely simple things is okay for something else, and you need to do the correct managed initialization.
source share