home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13373 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.4 KB  |  54 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!demos!news-server
  3. From:  David Tolpin <dat@infos.msk.su>
  4. Subject: Re: can I 'delete' without a 'new'?
  5. References: <66.66.0.999.2AA9B801@infos.msk.su>
  6. Date: Sun, 6 Sep 1992 17:00:05 GMT
  7. Reply-To: dat@infos.msk.su
  8. Organization: InfoSoft (Echo2News)
  9. Sender: news-server@kremvax.hq.demos.su
  10. Message-ID: <66.66.0.7.2aaa1687@infos.msk.su>
  11. Lines: 41
  12.  
  13. Hello peter@kentrox.uucp!
  14.  
  15. Friday September 04 1992 17:10, peter@kentrox.uucp wrote to All:
  16.  
  17.  pu:> I can't seem to find any references which indicate whether I can do this
  18.  pu:> or not, so I'm appealing to the net.wisdom.  Here's what I've got:
  19.  
  20.  pu:> class foo {
  21.  pu:>   char *String;
  22.  pu:> public:
  23.  pu:>   foo();
  24.  pu:>   foo( char * );
  25.  pu:>   ~foo();
  26.  pu:>   void set( char * );
  27.  pu:> };
  28.  
  29.  pu:> foo:foo() { };
  30.  
  31.  
  32.  pu:> foo:~foo() {
  33.  pu:>   delete [] String;
  34.  pu:> }
  35.  
  36.  pu:> The question is what will happen if I create a foo with the empty
  37.  pu:> constructor and never call 'set'?  Since 'new' has never been called,
  38.  pu:> what will 'delete' try to delete?  Looks like a real good way to frazzle
  39.  pu:> the system.  Yes?  No?
  40.  
  41. 1.Initialize pointers that are not allocated in the constructor. foo::foo() { 
  42. String = NULL; }
  43.  
  44. 2.After deleting a pointer that in a place other than destructor, assigns NULL 
  45. to it.
  46.  
  47. David Tolpin, Moscow, Russia
  48.  
  49. --- GED
  50.  * Origin: << David Tolpin from Northern Hills, dat@infos.msk.su > (66:66/0.7)
  51.  
  52.  
  53.  
  54.