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

Re: Returning a Struct from a Function

by "Alf P. Steinbach" <alfps@[EMAIL PROTECTED] > May 13, 2008 at 10:53 AM

* James Kanze:
> On May 12, 6:59 pm, Erik Wikström <Erik-wikst...@[EMAIL PROTECTED]
> wrote:
>> On 2008-05-12 18:42, Stefan Ram wrote:
> 
>>> =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?= <Erik-wikst...@[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.
> 
>> 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.

Huh?

But OK, it's 25:00 o' clock for me (in the day), so perhaps not at my 
sharpest.

But explanation of difference would be appreciated, cause I can't see it.


Cheers,

- Alf

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 




 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 15:58:47 CDT 2008.