🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #4074

Temporary objects in Std

#4074
From: Wei Peng
Date: Wed, 17 Apr 1996 14:57
35 lines
1632 bytes
Hi, I'm sure about what the Std says about the lifetime of temp objects (it
says tmp objects may live longer... or something alike).

A sample code. Suppose we have a string object called String, all necessary
constructors/operators are well defined. Now we have three functions

void doSomething(const char*);

String getString();

const char* getCharStar()
{
  return returnString();
}

Now if we do:

          doSomething(getCharStar());

Obvously this code doesn't work under old C++, where temp objects only
live within their scope. My impression is that under STD C++ the tmp
object created by getString() should live long enough so doSomething()
can safely execute.

But apparently some of the compilers I've tried still execute String
destructor when getCharStar() returns.

Wei Peng


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <4107cc$101229.223@news>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: peng@dpg.rnb.com (Wei Peng)
Newsgroups: comp.std.c++
Subject: Temporary objects in Std
Date: 17 Apr 1996 14:57:29 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4107cc$101229.223@news>
NNTP-Posting-Host: taumet.eng.sun.com
X-Newsreader: knews 0.9.6
Originator: clamage@taumet