mardi 26 octobre 2021

What is the order of destruction for static objects and global objects?

If in a program I create a meyer's singleton and an object that uses this meyer's singleton in both its constructor and destructor, things are okay as long as the object that uses meyer's singleton is destroyed before the singleton itself (like when it is in a function scope).

Now if I make the same object global, I see seg fault. The reason is that the singleton gets destroyed before the global object.

Is this a compiler defined behaviour or standard defined behaviour? Is there any way we can modify this behaviour?

Any pointers will be appreciated.

Aucun commentaire:

Enregistrer un commentaire