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 11 of 16 Topic 45864 of 47032
Post > Topic >>

Re: Returning a Struct from a Function

by "Victor Bazarov" <v.Abazarov@[EMAIL PROTECTED] > May 12, 2008 at 12:55 PM

Stefan Ram wrote:
> =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?= <Erik-wikstrom@[EMAIL PROTECTED]
> writes:
>>>> inline TwoFields ReturnMyFields(int myInt) {
>>>> TwoFields myReturnStruct; [...]
>>>> return myReturnStruct;
>> const TwoFields & f = ReturnMyFields(v);
>
>  How long will the object created with »TwoFields myReturnStruct;«
> live?
>
>  I used to believe that its lifetime would end not later than the
>  evaluation of the full expression »ReturnMyFields(v)« or even
>  when the control is leaving the block containing its declaration.

And what changed your mind? <g>

Actually, the tem****ary returned from the function, the object to
which 'f' is made to refer by means of initializing it, will live
as long as 'f' itself.  That's one of the exceptions the the rule
for the "normal" lifetime of a tem****ary (end of the expression).

V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
 




 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 Fri Jul 25 16:01:26 CDT 2008.