Re: Is this code wrong?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi John,

The style that you indicated...

Foo ReturnAFoo()
{
  Foo foo;
  return foo;
}

void DoSomething()
{
  Foo const& foo = ReturnAFoo();
  foo.AreYouStillHere(); // Yep, still here.
}

...is good.

The temporary returned by ReturnAFoo in DoSomething is bound to the
reference.

It won't be destructed until the reference goes out of scope.  Really.

I use that style often.

(Although I can't cite chapter+verse of ISO 14882.)

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux