&& is new in C ++ 11. int&& a means that "a" is a reference to an r-value. && usually used only to declare a function parameter. And it only accepts r-value expression. If you do not know what an r-value is, a simple explanation is that it does not have a memory address. For example. number 6, and the symbol "v" - both r values. int a , a is an l-value, however (a+2) is an r-value. For example:
void foo(int&& a) { //Some magical code... } int main() { int b; foo(b); //Error. An rValue reference cannot be pointed to a lValue. foo(5); //Compiles with no error. foo(b+3); //Compiles with no error. int&& c = b; //Error. An rValue reference cannot be pointed to a lValue. int&& d = 5; //Compiles with no error. }
Hope this is informative.
Lexseal Lin Sep 13 '16 at 23:05 2016-09-13 23:05
source share