Gal Goldman Gal Goldman - 1 year ago 119
C++ Question

Destruction order of static objects in C++

Can I control the order static objects are being destructed?
Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object?

Answer Source

The static objects are destructed in the reverse order of construction. And the order of construction is very hard to control. The only thing you can be sure of is that two objects defined in the same compilation unit will be constructed in the order of definition. Anything else is more or less random.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download