Difference between c++11 vs c++03

Posted by aiao on Stack Overflow See other posts from Stack Overflow or by aiao
Published on 2012-12-06T22:36:23Z Indexed on 2012/12/06 23:03 UTC
Read the original article Hit count: 112

Filed under:
|
|
|

I have spend a few hours about rvalue s and lvalue. Here is what I understand

int main()
{
  //.....
  Foo foo = Bar1();
  Foo foo = Bar2();
  //......
}  

Foo Bar1()
{
  //Do something
  return foo;
}

Foo& Bar2()
{
  //Do something
  return foo;
}

Under c++03, Bar1() would copy the return object (just before return), and then return the address of the copied object; executing a wasteful copy of an object which is about to be destroyed. Bar2() would return the object created within the function.

Under c++11, Bar1() and Bar2() would essentially be equivalent (and also equivalent to Bar2() of c++03).

Is that right? If not, please elaborate.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c++11