home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18232 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.1 KB

  1. Path: sparky!uunet!gatech!prism!federation!andy
  2. From: andy@federation.gatech.edu (Andy Register)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Should char arrays be deleted with delete[]?
  5. Keywords: C++
  6. Message-ID: <78593@hydra.gatech.EDU>
  7. Date: 18 Dec 92 18:53:13 GMT
  8. References: <1992Dec18.161338.28124@promis.com>
  9. Sender: news@prism.gatech.EDU
  10. Organization: CERL-EE, Georgia Institue of Technology
  11. Lines: 25
  12.  
  13. In article <1992Dec18.161338.28124@promis.com> fogel@promis.com (Richard Fogel) writes:
  14. >Should char strings allocated as follows:
  15. >
  16. >char *str = new char[10];
  17. >
  18. >later be deleted by:
  19. >
  20. >delete []str   OR    delete str  ?
  21.  
  22.  
  23. To quote from Meyers, "In the case of an object type like char that has no
  24. destructor, this issue isn't important, but in general this is something
  25. you do not want to forget.  *Always* make sure that you use [] with 
  26. delete if and only if you used [] with the corresponding call to new."
  27.  
  28. Item 11 btw.
  29.  
  30. So, use either syntax for str but I would advocate using the [] syntax
  31. so that you get used to it and automatically use it in cases
  32. where it matters.
  33.  
  34. Toodles
  35. Andy
  36.  
  37.  
  38.