Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Advanced
May 12, 1999



Application Security Testing: An Integral Part of DevOps

Optimize With the Named Return Value

The named return value is an automatic optimization that a compiler applies in order to eliminate the construction and destruction of a temporary object. When a temporary object is copied to another object using a copy constructor, and none of these objects is const or volatile, the Standard allows the implementation to treat the two objects as one, and not perform a copy at all.
  class A {
    A(const A&);
    A operator=(const A&);

  A f()  //return A by value
    A a1;
    return a;

  A a2 = f();
The object a1 does not need to be copied when f() returns. Instead, the return value of f() can be constructed directly into the object a2, thereby avoiding both the construction and destruction of a temporary object on the stack.
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date