home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13282 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.0 KB  |  54 lines

  1. Path: sparky!uunet!ogicse!plains!plains.NoDak.edu!heilig
  2. From: heilig@plains.NoDak.edu (Zachary Heilig)
  3. Newsgroups: comp.lang.c++
  4. Subject: delete this???
  5. Message-ID: <20146@plains.NoDak.edu>
  6. Date: 4 Sep 92 02:29:27 GMT
  7. Article-I.D.: plains.20146
  8. Sender: Unknown@plains.NoDak.edu
  9. Organization: North Dakota Higher Education Computing Network
  10. Lines: 41
  11. Nntp-Posting-Host: plains.nodak.edu
  12.  
  13.  
  14. I saw the previous thread about calling the destructor in member functions,
  15. and was wondering how legal the following code would be:
  16.  
  17. --foo.c--
  18. class foo {
  19.     int    *bar;
  20. public:
  21.         foo();
  22.         ~foo();
  23.     void    remove( int = 1 );
  24. }
  25.  
  26. foo::foo()
  27. {
  28.     bar = new int[100];
  29. }
  30.  
  31. foo::~foo()
  32. {
  33.     remove( 0 );
  34. }
  35.  
  36. void foo::remove( int call_destruct )
  37. {
  38.     if( bar ) delete bar;
  39.     if( call_destruct ) delete this;
  40. }
  41. --end--
  42.  
  43. or, should I just call the destructor function?
  44.  
  45. any ideas?
  46.  
  47. -- 
  48.     - Zach Heilig (heilig@plains.nodak.edu)
  49.  
  50. Ninety-Ninety Rule of Project Schedules:
  51.     The first ninety percent of the task takes ninety percent of
  52.     the time, and the last ten percent takes the other ninety
  53.     percent.
  54.