Sequence of calling constructor and destructor
The first constructor and the second constructor.
When to call constructor and destructor
(1) An object defined in a global scope. Its constructor is executed before all functions in the file are executed. However, whenProgramWhen multiple files are defined and global variables are defined in different files, the call sequence of the object constructor is uncertain. When the main function ends or the exit function is run, call destructor
(2) when defining a partial automatic object, the object is created to call its constructor. If a function is called multiple times, you must call the constructor after each object creation. At the end of the function call, you can call the destructor.
(3) When a static object is defined as static, the constructor is called only once when the object is created. When the main function is completed or exit, the Destructor is called.