How to run code before the main function in C++
This article is about running code before the main function in C++. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
Run code before main function
Global objects are constructed before the program starts, and this function returns before main() starts.
For example:
class Logger{public: Logger() { activate_log(); } void activate_log() { cout