On Sat, 1 Jun 2013 08:13:23 PM Milian Wolff wrote:
> > >   const Akonadi::Item &item = mFetchedItemList.takeFirst();
> > > 
> > >
> > > and
> > >
> > > 
> > >   const Akonadi::Item item = mFetchedItemList.takeFirst();
> > > 
> > >
> > > are basically the same.
> 
> See also:
> http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important
> -const/

Excellent link! that clarified the scope and lifetime for me.

This is what I thought happened:

 / "Normally, a temporary object lasts only until the end of the full 
expression in which it 
appears. "/

Which would have been a problem.

But the following clarification explains why not:

/"However, C++ deliberately specifies that binding a temporary object to a 
reference to 
const on the stack lengthens the lifetime of the temporary to the lifetime of 
the 
reference itself, and thus avoids what would otherwise be a common 
dangling-reference 
error."/

-- 
Lindsay

Attachment: signature.asc
Description: This is a digitally signed message part.

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

Reply via email to