Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PODs, non-PODs, rvalue and lvalues

Tags:

People also ask

What is lvalue and rvalue with example?

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.

What is an xvalue?

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.

What is value category in C++?

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; }