C++C++11Syntax

Learn The Initialization Of Class Objects By Rvalues When Building Windows Apps In C++

C++Builder includes the use of rvalue references, which allow creating a reference to temporaries. When you initialize to an class object using an rvalue(a temporary object), C++11 looks to see if you have defined a move constructor in your class. If you have, the temporary object is passed to it as a modifiable (non-const) rvalue reference, allowing you to transfer ownership of resource pointers and handles, and nullify them in the temporary object. We can implement the move constructor as follows.
Here use the syntax && to indicate that the variable is an rvalue reference. When the temporary object is initialized, we now simply copy the pointer instead of the content it points to. Head over and check out all of the C++ features supported by the Clang compiler in C++Builder.
close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is An Eligible Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What Is A Trivial Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What Is Uppercase T in C++ Syntax?

C++C++11C++14C++17Learn C++Syntax

What Is An Implicitly-defined Copy Assignment Operator In C++?