Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mat1515

Class Deconstructor

This topic is 5277 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

Advertisement
Yes. The only exception is when the program is destroyed using abort () call. Then it doesn''t call anything and crashes very quickly (which is what you want).

Oxyd

---
- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
...only if they''ve gone out of scope. If you allocated them with the new operator, then you must delete them somewhere before the end of the program.

Share this post


Link to post
Share on other sites
Also, with my compiler (VC++ 6) a global object''s destructor is not called ever. Only if it is in a local scope somewhere will the destructor be called.

Btw, it''s really annoying and I want a better compiler

Share this post


Link to post
Share on other sites
quote:
Original post by Henners
Also, with my compiler (VC++ 6) a global object''s destructor is not called ever. Only if it is in a local scope somewhere will the destructor be called.



That is strange, I am using Microsoft Visual C++ 6.0, and all of my global objects get their destructors called. I wonder what could be wrong????

Is there anyone who can shed more light on this?

- Ratterbox

Share this post


Link to post
Share on other sites
quote:
Original post by Henners
Also, with my compiler (VC++ 6) a global object's destructor is not called ever. Only if it is in a local scope somewhere will the destructor be called.


I'd like to know how you check whether your dtor is run or not...
I use VC6 and I find that every implicitly allocated object (not one allocated with new) is destroyed and its dtor is called upon program exit.


[edited by - amag on March 8, 2004 5:55:53 PM]

Share this post


Link to post
Share on other sites
You cannot accurately predict what order static object instances will construct and destruct.

Not sure if that has anything to do with anything, but there you go.

Share this post


Link to post
Share on other sites
Something''s wrong on your part man, I''m using the MSVS6 C++ IDE and I haven''t run into any problems. I have a global class called Game, which is declared like you declare "int x" as opposed to being declared dynamically using the new operator, and Game''s deconstructor runs just fine. I placed a breakpoint at the beginning of Game''s deconstructor, and normally exited my game and indeed the deconstructor ran.

Share this post


Link to post
Share on other sites
quote:
3.7.1 Static storage duration [basic.stc.static]
1 - All objects which neither have dynamic storage duration nor are local have static storage duration . The storage for these objects shall last for the duration of the program (3.6.2, 3.6.3).

3.6.3 Termination [basic.start.term]
1 - Destructors (&2.4) for initialized objects of static storage duration (declared at block scope or at namespace scope) are called as a result of returning from main and as a result of calling exit (18.3). These objects are destroyed in the reverse order of the completion of their constructor or of the completion of their dynamic initialization. If an object is initialized statically, the object is destroyed in the same order as if the object was dynamically initialized. For an object of array or class type, all subobjects of that object are destroyed before any local object with static storage duration initialized during the construction of the subobject is destroyed.

4 - Calling the function void abort(); declared in <cstdlib> terminates the program without executing destructors for objects of automatic or static storage duration and without calling the functions passed to atexit().




“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)


[edited by - Fruny on March 8, 2004 6:41:16 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!