Guaranteed order?

Started by
1 comment, last by MortusMaximus 15 years, 5 months ago
if i created 5 class would it be Guaranteed that their destructor will call in the reserve order? No matter how crazy my optimizations are? I have several classes that are call C init and cleanup code so if they are shuffled *very* bad things will happen.
<SkilletAudio> Your framerate proves your lack of manhood
Advertisement
Quote:Original post by AcidZombie24
if i created 5 class would it be Guaranteed that their destructor will call in the reserve order?

Local variables are guaranteed to be destroyed in reverse order of their construction, yes (if that's what you asked).
I believe they are, yes. If you have to be absolutely sure, give the class an int ID, and cout (or messagebox, or whatever) the ID at the end of the constructor and in the destructor, and make sure they come out the way you think it will.

If your "optimizations" rely on this happening, though, you might want to re-think the optimizations. With the growing power of computers, a lot of computational power goes to waste anyway, so robustness is generally more important than efficiency, to ensure that your code will work on a wide variety of C++ implementations.
Check out the first gameplay video from my javascript/PHP RTS game

This topic is closed to new replies.

Advertisement