How are the && and & parameters different in C++
Implemented from C++11
More objectively we can say, for example, that:
Of course, values and types are examples.
But in summary, one is the
lvalue and the other is the
In C++03 (and before), temps (called “rvalues”, as they often lie on the right side of an assignment) were designed to never be modifiable - just as in C - and were considered indistinguishable from
const types T&; , however, in some cases the temps may have been modified, a behavior that was even considered a useful loophole.
C++11 adds a new non-const reference type called the rvalue reference, identified by
T&&. Refers to temporaries that can be modified after they are initialized, for the purpose of allowing “semantic move”.
&&as a parameter, let’s look at the output:
That is, a pointer to an rvalue value, but the pointer to itself.
One more example below using
Of course this output will only be the value
I personally don’t see any use for this in the code I create, but this article is for us to know what it means when we see a double ampersand in some code and understand how they are used and what values are returned.
That’s all for today, small daily doses that will always keep us in tune with C++!