Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!columbia!read.columbia.edu!kearns From: kearns@read.columbia.edu (Steve Kearns) Newsgroups: comp.lang.c++ Subject: lifetime of temporary objects Message-ID: <6374@columbia.edu> Date: 24 Jun 89 22:12:42 GMT Sender: news@columbia.edu Reply-To: kearns@read.UUCP () Organization: Columbia University Department of Computer Science Lines: 27 On pg. 43 of the "bible" it says: "an object is created when its definition is encountered and destroyed when its name goes out of scope." What about temporary variables: for example, with the following declarations... struct foo {int * dummy...}; foo foo::make(); int bar(int); ... is the lifetime of the temporary "foo" returned by foo (below) guaranteed not to be destructed until after bar returns? bar(make().dummy); This can be important when doing reference counting. The above code is more efficient than the alternative: // define bar to take a ref instead int bar(foo& ) // call bar this way bar(make()); -steve (kearns@cs.columbia.edu)