Modern compilers typically implement the (Named) Return Value Optimization, by which the copy you reference (and would logically expect) is not done.
Ever since Visual Studio 2005 (VC++ 8.0) I don’t think twice about returning objects.
More Related Contents:
- Why ‘&’ reference in not required in classes in C++?
- What are the differences between a pointer variable and a reference variable in C++?
- When to use references vs. pointers
- When should I use the new keyword in C++?
- Pointer vs. Reference
- Reason to Pass a Pointer by Reference in C++?
- C++ pass an array by reference
- C++ standard: dereferencing NULL pointer to get a reference? [duplicate]
- How are references implemented internally?
- difference between a pointer and reference parameter?
- What are the differences between a pointer variable and a reference variable?
- Passing references to pointers in C++
- What’s the meaning of * and & when applied to variable names?
- Function pointer vs Function reference
- error: invalid initialization of non-const reference of type ‘int&’ from an rvalue of type ‘int’
- What is the difference between std::reference_wrapper and a simple pointer?
- Difference between const. pointer and reference?
- Confusion about pointers and references in C++
- Returning non-const reference from a const member function
- Why do some people prefer “T const&” over “const T&”?
- Use const wherever possible in C++?
- Where ampersand “&” can be put when passing argument by reference?
- Why isn’t operator overloading for pointers allowed to work?
- C++ strings: [] vs. *
- Why is a c++ reference considered safer than a pointer?
- C++ function called without object initialization
- Meaning of *& and **& in C++
- Pass by pointer & Pass by reference [duplicate]
- Reference to a pointer
- Both asterisk and ampersand in a parameter