21. The order of construction of objects

For local objects: Constructed when the flow of program execution reaches the object's definition statement.

For heap objects, the object is created when the program execution flow reaches the new statement, and creating an object with new will automatically trigger the invocation of the constructor.

For global objects, the construction order of the objects is undefined, and different compilers use different rules to determine the construction order.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325885012&siteId=291194637
21.