Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeRAD Studio

Learn About The Initialization Of Class Objects By Rvalues In C++ Windows Development

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.


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

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
CodeDatabaseDelphiRAD Studio

Quickly Learn How Easy It Is To Bind DataSets To Visual Controls In Delphi With LiveBindings

C++CodeRAD Studio

Learn How To Use C++ Incomplete Return Types In Windows Development

C++Delphi

Create Beautiful Windows Applications With Visually Stunning VCL Styles For Delphi And C++

CodeDelphiRAD Studio

Master A Powerful Way To Execute Multiple SQL Commands In Delphi With This Windows Sample

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES