home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!agate!tfs.com!tfs.com!eric
- From: eric@tfs.com (Eric Smith)
- Subject: Re: Destruction of temporaries
- Message-ID: <1992Sep2.223451.24804@tfs.com>
- Organization: TFS
- References: <rmartin.715267769@thor> <1992Sep2.042030.488@frumious.uucp> <1992Sep2.192339.2774@lucid.com>
- Date: Wed, 2 Sep 1992 22:34:51 GMT
- Lines: 21
-
- In article <1992Sep2.192339.2774@lucid.com> jss@lucid.com (Jerry Schwarz) writes:
- > h( ostrstream() ) ;
- >
- >but not
- >
- > h ( ostrstream() << "contents" << ends ) ;
-
-
- Wrong. Both calls are with a temporary. Both should be equally illegal.
-
- You should construct the stream object, give it a name, and use it as
- above. Then neither of the above will be temporaries.
-
- e.g. h ( mystream << "contents" << ends ) ;
- returns a reference to mystream, which is not a temporary.
- (And each subexpression returns a reference to mystream, so
- there are no temporaries involved.)
-
- A temporary is an object constructed for a single expression. Calling a
- function with that expression is ok only if the function does not assume
- the object will still exist after the function returns.
-