Thread: Order of Object Destruction

  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.?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    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
    Ireland
    Posts
    8,446
    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.
    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, 11: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