Sign in to follow this  

Guaranteed order?

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this