] Assigning to rvalue
时间: 2024-05-25 21:10:45 浏览: 11
Assigning to an rvalue is not allowed in C++. An rvalue is a temporary value that does not persist beyond the expression in which it was created. It cannot be assigned to because it does not have a memory location. For example, the result of a function call that returns by value is an rvalue. It is not possible to assign to the result of a function call that returns by value because it is an rvalue.
In contrast, an lvalue is a value that has a memory location and can be assigned to. For example, a variable declared with a name is an lvalue. It has a memory location, and its value can be changed by assignment.
Therefore, attempting to assign to an rvalue in C++ will result in a compile-time error.