Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Returning a...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 13 of 16 Topic 45864 of 47006
Post > Topic >>

Re: Returning a Struct from a Function

by James Kanze <james.kanze@[EMAIL PROTECTED] > May 13, 2008 at 01:50 AM

On May 12, 6:59 pm, Erik Wikstr=F6m <Erik-wikst...@[EMAIL PROTECTED]
> wrote:
> On 2008-05-12 18:42, Stefan Ram wrote:

> > =3D?UTF-8?B?RXJpayBXaWtzdHLDtm0=3D?=3D <Erik-wikst...@[EMAIL PROTECTED]
>
writes:=

> >>>>inline TwoFields ReturnMyFields(int myInt) {
> >>>>TwoFields myReturnStruct; [...]
> >>>>return myReturnStruct;
> >>const TwoFields & f =3D ReturnMyFields(v);

> >   How long will the object created with =BBTwoFields
> >   myReturnStruct;=AB live?

> >   I used to believe that its lifetime would end not later
> >   than the evaluation of the full expression
> >   =BBReturnMyFields(v)=AB or even when the control is leaving
> >   the block containing its declaration.

> When you bind a tem****ary to a const reference the lifetime of
> the tem****ary is extended to last as long as the reference.

That can easily be misunderstood (and often is).  Formally, the
rule is when the initialization expression of a reference is a
tem****ary, the lifetime of the tem****ary is extended to
correspond to the lifetime of that reference.  Which isn't quite
the same thing.

--
James Kanze (GABI Software)             email:james.kanze@[EMAIL PROTECTED]
 en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
 




 16 Posts in Topic:
Returning a Struct from a Function
alex.j.k2@[EMAIL PROTECTE  2008-05-11 10:57:38 
Re: Returning a Struct from a Function
john <john@[EMAIL PROT  2008-05-11 20:02:06 
Re: Returning a Struct from a Function
alex.j.k2@[EMAIL PROTECTE  2008-05-11 11:18:16 
Re: Returning a Struct from a Function
"Alf P. Steinbach&qu  2008-05-11 20:45:46 
Re: Returning a Struct from a Function
peter koch <peter.koch  2008-05-11 11:19:09 
Re: Returning a Struct from a Function
alex.j.k2@[EMAIL PROTECTE  2008-05-11 11:33:42 
Re: Returning a Struct from a Function
alex.j.k2@[EMAIL PROTECTE  2008-05-11 12:36:41 
Re: Returning a Struct from a Function
Gianni Mariani <gi4nos  2008-05-11 22:33:22 
Re: Returning a Struct from a Function
=?UTF-8?B?RXJpayBXaWtzdHL  2008-05-12 16:31:55 
Re: Returning a Struct from a Function
ram@[EMAIL PROTECTED] (S  2008-05-12 16:42:36 
Re: Returning a Struct from a Function
"Victor Bazarov"  2008-05-12 12:55:52 
Re: Returning a Struct from a Function
=?UTF-8?B?RXJpayBXaWtzdHL  2008-05-12 16:59:34 
Re: Returning a Struct from a Function
James Kanze <james.kan  2008-05-13 01:50:00 
Re: Returning a Struct from a Function
"Alf P. Steinbach&qu  2008-05-13 10:53:15 
Re: Returning a Struct from a Function
mojmir <svobodamo@[EMA  2008-05-14 01:37:03 
Re: Returning a Struct from a Function
Richard Herring <junk@  2008-05-20 09:55:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:51:18 CDT 2008.