Order of Object Destruction

This is a discussion on Order of Object Destruction within the C++ Programming forums, part of the General Programming Boards category; Do I have any control over torder in which objects are destructed? Is this standard? I am asking because I ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Order of Object Destruction

    Do I have any control over torder in which objects are destructed? Is this standard? I am asking because I am thinking about how I might handle fatal errors in an application and thought about using RAII to make some things are destroyed. But sometimes, some objects might be dependant on another objects existance to be destroyed correctly (example, a device context object would need an hwnd to exist). Is it even appropriate to make RAII self-cleanup thingies for hwnd's, dc's, rc's, etc.?

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,488
    Well, RAII is exactly one answer (when used correctly of course) to problems derived from object destruction. The key notion behind the type of control you want is that of "object ownership" and under it, yes. You will have control on how and when an object is destroyed. Usually by relaying that control to the implementation part of your class.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  2. Replies: 4
    Last Post: 11-14-2006, 10:52 AM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. ERRPR: Object reference not set to an instance of an object
    By blackhack in forum C++ Programming
    Replies: 1
    Last Post: 07-13-2005, 05:27 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21