home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16336 < prev    next >
Encoding:
Text File  |  1992-11-15  |  1.5 KB  |  34 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!think.com!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!meibm31.cen.uiuc.edu!pl2440
  3. From: pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas)
  4. Subject: Re: How to run destructors of all objects when failure exit occurs ?
  5. References: <AAAsb0h8xN@inpbox.inp.nsk.su>
  6. Message-ID: <BxsFJE.6GL@news.cso.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: University of Illinois at Urbana
  9. Date: Mon, 16 Nov 1992 02:42:50 GMT
  10. Lines: 22
  11.  
  12. In <AAAsb0h8xN@inpbox.inp.nsk.su> dolgov@inpbox.inp.nsk.su (Yuri V. Dolgov) writes:
  13.  
  14. >   Often I use failure program exit when some conditions are bad.
  15. >The trouble is: I created some objects (e.g. dialog boxes, network connections
  16. >and so on) and I want to run destructors before program exit.
  17. >Is there exist standard technique in C++ language to solve this problem ?
  18.  
  19.     No; only statically-allocated objects are destroyed.  Off the
  20.     top of my head, *a* way to have auto-objects destroyed would be
  21.     to make them register themselves with some global list of
  22.     objects on construction and deregister themselves on
  23.     destruction.  Now, when the global "clean-up" object gets
  24.     destroyed, it could destroy all objects that are still
  25.     registered.
  26.  
  27.     Actually, they can't be auto objects, but must instead be
  28.     dynamically-allocated objects; it is illegal to delete anything
  29.     not allocated by new (as auto objects aren't).
  30. -- 
  31.     - Paul J. Lucas                University of Illinois    
  32.       AT&T Bell Laboratories        at Urbana-Champaign
  33.       Naperville, IL            pjl@cs.uiuc.edu
  34.