What does rvalue reference mean in C ++

C ++ double address operator? (&&)

I am reading STL source code and have no idea what the address operator is supposed to do. Here is a code example from:

Does "address of address" make sense? Why are there two address operators instead of just one?


This is C ++ 11 code. In C ++ 11, the token can be referred to as "rvalue reference".

is new in C ++ 11. "a" means an r-value reference. is usually only used to declare a parameter of a function. And it takes just an r-value expression. If you don't know what an r-value is, the simple explanation is that it has no memory address. For example, the number 6 and the character 'v' are both r-values. a is an l-value but is an r-value. For example:

Hope this is informative.

is new in C ++ 11 and means that the function accepts an RValue reference, ie a reference to an argument that is to be destroyed.

As other answers have already mentioned, in this context the token is new to C ++ 0x (the next C ++ standard) and represents a "rvalue reference".

R-Value References are one of the most important new things in the upcoming standard. They enable the support of the movement semantics of objects and enable the perfect forwarding of function calls.

It's a pretty complex subject - one of the best introductions (and it's not just fleeting) is an article by Stephan T. Lavavej, "Rvalue References: C ++ 0x Features in VC10, Part 2".

Note that the article is still pretty hard to read, but well worth it. And while this is a Microsoft VC ++ blog, all (or almost all) of the information is applicable to any C ++ 0x compiler.

I believe this is a move operator. is for example the assignment operator. The function call sounds like it is deleting the contents of the vector to prevent a memory leak. The operator returns a pointer to the new vector.

This way,

Although we have given values ​​to vector a, vector b has the values. It's the magic of!

MSDN - How to create a move constructor

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.