For example, An assignment expects an lvalue as its left operand, so the following is valid: int i = 10; But this is not: int i; 10 = i; This is because i has an address in memory and is a lvalue. While 10 doesn't have an identifiable memory location and hence is an rvalue.
An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that its resources may be moved, for example). An xvalue is the result of certain kinds of expressions involving rvalue references.
Every C++ expression has a type, and belongs to a value category. The value categories are the basis for rules that compilers must follow when creating, copying, and moving temporary objects during expression evaluation.
Could anyone explain the details in terms of rvalues, lvalues, PODs, and non-PODs the reason why the first expression marked below is not ok while the second expression marked below is ok? In my understanding both int() and A() should be rvalues, no?
struct A {}; int main() { int i; A a; int() = i; //Not OK (error). A() = a; //OK. return 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With