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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!agate!tfs.com!tfs.com!eric
  3. From: eric@tfs.com (Eric Smith)
  4. Subject: Re: Destruction of temporaries
  5. Message-ID: <1992Sep2.223451.24804@tfs.com>
  6. Organization: TFS
  7. References: <rmartin.715267769@thor> <1992Sep2.042030.488@frumious.uucp> <1992Sep2.192339.2774@lucid.com>
  8. Date: Wed, 2 Sep 1992 22:34:51 GMT
  9. Lines: 21
  10.  
  11. In article <1992Sep2.192339.2774@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
  12. >    h( ostrstream() ) ;
  13. >
  14. >but not 
  15. >
  16. >    h ( ostrstream() << "contents" << ends ) ;
  17.  
  18.  
  19. Wrong.  Both calls are with a temporary.  Both should be equally illegal.
  20.  
  21. You should construct the stream object, give it a name, and use it as
  22. above.  Then neither of the above will be temporaries.
  23.  
  24. e.g.  h ( mystream << "contents" << ends ) ;
  25. returns a reference to mystream, which is not a temporary.
  26. (And each subexpression returns a reference to mystream, so
  27. there are no temporaries involved.)
  28.  
  29. A temporary is an object constructed for a single expression.  Calling a
  30. function with that expression is ok only if the function does not assume
  31. the object will still exist after the function returns.
  32.