home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!rde!gator!fang!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.lang.c++
- Subject: Re: destruction of temporaries
- Message-ID: <23507@alice.att.com>
- Date: 20 Aug 92 21:16:28 GMT
- Article-I.D.: alice.23507
- References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com> <3920@starlab.UUCP> <23487@alice.att.com> <TMB.92Aug20142610@arolla.idiap.ch>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Murray Hill NJ
- Lines: 21
-
- In article <TMB.92Aug20142610@arolla.idiap.ch> tmb@idiap.ch writes:
-
- > You can avoid unexpected behavior involving temporaries by programming
- > defensively. In particular, this means: do _not_ return a reference or
- > pointer to an explicit or implicit argument or its contents (*this,
- > call-by-value, call-by-reference). Furthermore, do _not_ define cast
- > operators to pointer types in your classes (instead, make them normal
- > member functions that you have to call explicitly).
-
- I wish life were that simple. The trouble comes with expressions like
-
- foo().bar().baz()
-
- where bar returns *this. If an implementation is allowed to delete the
- result of foo() before calling baz, the roof can cave in even if your
- defensive rules are followed. That is enough to argue, at least for me,
- that the current rule of allowing temporaries to be destroyed as soon as
- they are fetched, is too liberal.
- --
- --Andrew Koenig
- ark@europa.att.com
-