I have been learning Effective C++ and in one of the guidelines Meyer mentions that if we declare a non-local static object in one translation unit with its definition in another translation unit it results in undefined behaviour. This problem is fixed by writing a function that returns a reference to a local static object.
My question is that:
How do local static objects govern compilation of various translation units?
How does the compiler know which translation unit to execute first?
And my apologies if asked the question in a bit incorrect way. I hope you understood what I meant.
Aucun commentaire:
Enregistrer un commentaire