home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17985 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.6 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Temporaries
  5. Message-ID: <1992Dec15.143406.5353@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec6.204110.3073@news.cs.brandeis.edu>
  10. Date: Tue, 15 Dec 1992 14:34:06 GMT
  11. Lines: 51
  12.  
  13. In article <1992Dec6.204110.3073@news.cs.brandeis.edu> dernis@binah.cc.brandeis.edu writes:
  14. >Hi,
  15. > Could someone explain how temporaries are identified and handled?
  16.  
  17.     A class with properly defined constructors and destructors will
  18. be handled 'just like an int'.
  19.  
  20. >If an overloaded operator produces a temporary(by declaring a new variable)
  21. >to hold the result of an arithemetic op how is it destroyed?  
  22.  
  23.     Wrong question. Right question: *When* is it destroyed?
  24.     Answer: it is implementation defined, the upcoming standard
  25.     ought to have more words on this, however.
  26.  
  27. >What if the
  28. >operator returns a pointer to it?  Is the compiler smart enough not to destroy
  29. >it?  
  30.  
  31.     Same as if the object was an int. Return a pointer to an object
  32. on the stack, the pointer dangles. Return a pointer to a heap object,
  33. its up to you to delete it. Best to return a copy of the object,
  34. then the compiler deletes it.
  35.  
  36. >
  37. >If it an object with an array type allocated dynamically, the destructor will 
  38. >have to include a delete statement to get rid of the array, right?  If info is 
  39. >passed by reference then two objects will share the same array, if one of the 
  40. >objects is destroyed what happens to the array?  
  41.  
  42.     It is deleted, just like you told the system to delete it.
  43. The other reference is trash. Same as for int.
  44. >
  45. >I would appreciate an answer on the net, either a response or FAQ list 
  46. >(how do you access the FAQ list?).  I am out of money after buying the
  47. >computer, compiler, and Lippman's book C++ Primer.  Does he discuss
  48. >this?  I couldn't find it, but I haven't really looked through it
  49. >thoroughly?
  50.  
  51.     None of these issues really differ from the same questions
  52. in C. All that differs is that you can now make new types
  53. that act like 'int'.
  54.  
  55.     While there are other techniques, using this idiom
  56. is a good was to start off. See Coplien for explict details of how to
  57. write classes using the Orthodox Idiom.
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.