Answer the question
In order to leave comments, you need to log in
How is an rvalue reference different from an lvalue reference?
Good afternoon. If I'm not mistaken, then an lvalue reference &r
can refer to the memory address of a named object (variable). So, an rvalue reference &&rr
is the same as an lvalue reference, only it can refer to a temporary object? (for example, a literal 5
)
I show by example that they are similar:
int x = 5;
int &r = x; //lvalue-ссылка
r = 10;
cout << x; //в консоли: 10
//другой пример:
int x = 5;
int &&rr = move(x); //rvalue-ссылка
rr = 10;
cout << x; //в консоли: 10
int x = 5;
inr &r = x; //work
int &r = 10; //nope
int &&rr = x; //nope
int &&rr = move(x); //work
int &&rr = 10; //work
Answer the question
In order to leave comments, you need to log in
then what is the benefit of using rvalue references in move semantics
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question