rvalue

Are literal strings and function return values lvalues or rvalues?

帅比萌擦擦* 提交于 2019-11-26 04:44:25
问题 Just wonder if a literal string is an lvalue or an rvalue. Are other literals (like int, float, char etc) lvalue or rvalue? Is the return value of a function an lvalue or rvalue? How do you tell the difference? 回答1: string literals are lvalues, but you can't change them rvalue, but if it's a pointer and non-NULL, the object it points to is an lvalue The C standard recognizes the original terms stood for left and right as in L = R ; however, it says to think of lvalue as locator value , which

Why is ++i considered an l-value, but i++ is not?

不羁岁月 提交于 2019-11-26 03:07:37
问题 Why is ++i is l-value and i++ not? 回答1: Well as another answerer pointed out already the reason why ++i is an lvalue is to pass it to a reference. int v = 0; int const & rcv = ++v; // would work if ++v is an rvalue too int & rv = ++v; // would not work if ++v is an rvalue The reason for the second rule is to allow to initialize a reference using a literal, when the reference is a reference to const: void taking_refc(int const& v); taking_refc(10); // valid, 10 is an rvalue though! Why do we

Rvalue Reference is Treated as an Lvalue?

有些话、适合烂在心里 提交于 2019-11-26 00:29:21
问题 I posted this answer: https://stackoverflow.com/a/28459180/2642059 Which contains the following code: void foo(string&& bar){ string* temp = &bar; cout << *temp << \" @:\" << temp << endl; } Is bar an rvalue or an lvalue? I ask because I obviously cannot take the address of an rvalue, yet I can take the address of an rvalue reference as is done here. If you can perform any operation on an rvalue reference that you can on an lvalue reference what is the point in differentiating between the two