Questions tagged [lvalue]

L-value represents the address of the value. "L" stands for the left side, because the address it is what is required when the variable appears on the left side of an assignment operation.

661 questions
10
votes
5 answers

lvalue required

what does the error message "Lvalue required" actually mean?
alfesani
  • 451
  • 2
  • 6
  • 11
10
votes
2 answers

difference between rvalue reference and lvalue reference as argument

After reading the post:http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html. I can not figure out that when you write functions that take lvalue or rvalue references as arguments, such as this: void printReference…
sydridgm
  • 1,012
  • 4
  • 16
  • 30
10
votes
5 answers

Reference initialization in C++

Can anybody explain to me why there is a difference between these two statements? class A{}; const A& a = A(); // correct A& b = A(); // wrong It says invalid initialization of non-const reference of type A& from a…
skydoor
  • 25,218
  • 52
  • 147
  • 201
10
votes
5 answers

Javascript Ternary Operator lvalue

I was reading about the ternary operator in different languages, and noticed something interesting in the Javascript section. http://en.wikipedia.org/wiki/%3F:#JavaScript The conditional operator in JavaScript has the same syntax and precedence…
Ryan Dignard
  • 639
  • 1
  • 5
  • 16
9
votes
4 answers

How is assignments to compound literals useful?

I was reading about compound literals, and I saw that they are l-values. So I suspected that you can assign them, so I did an experiment and I noticed that this compiles without warnings with gcc -Wall -Wextra -pedantic: struct foo { int x; …
klutt
  • 30,332
  • 17
  • 55
  • 95
9
votes
4 answers

lvalue required as increment operand error

#include int main() { int i = 10; printf("%d\n", ++(-i)); // <-- Error Here } What is wrong with ++(-i)? Please clarify.
Wei
  • 93
  • 1
  • 3
9
votes
3 answers

Check if a subroutine is being used as an lvalue or an rvalue in Perl

I'm writing some code where I am using a subroutine as both an lvalue and an rvalue to read and write database values. The problem is, I want it to react differently based on whether it is being used as an lvalue or an rvalue. I want the subroutine…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
9
votes
1 answer

Where in the C++ Standard does it say ::delete can change lvalues?

I ran into my first compiler that changes the lvalue passed to ::delete, but doesn't zero out the lvalue. That is the following is true: Foo * p = new Foo(); Foo * q = p; assert(p != 0); assert(p == q); ::delete p; assert(p != q); assert(p !=…
Ants
  • 2,628
  • 22
  • 35
9
votes
2 answers

error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector::reference {aka std::_Bit_reference}’

Why do I get the error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector::reference {aka std::_Bit_reference}’? vector> vis; bool& visited(int x, int y) { return vis[x][y];…
Mariusz Trela
  • 103
  • 1
  • 9
9
votes
1 answer

why does --list.end() compile?

list's end() returns a copy of the past-the-end iterator, right? Therefore, list.end() is an rvalue, right? the -- operator-function overloaded for list iterator takes a non-const reference, right? you can't bind rvalues to non-const references,…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
9
votes
4 answers

Why are multiple increments/decrements valid in C++ but not in C?

test.(c/cpp) #include int main(int argc, char** argv) { int a = 0, b = 0; printf("a = %d, b = %d\n", a, b); b = (++a)--; printf("a = %d, b = %d\n", a, b); return 0; } If I save the above as a .cpp file, it compiles and outputs…
mkosler
  • 322
  • 2
  • 7
9
votes
1 answer

c++: function lvalue or rvalue

I just started learning about rvalue references in c++11 by reading this page, but I got stuck into the very first page. Here is the code I took from that page. int& foo(); foo() = 42; // ok, foo() is an lvalue int* p1 = &foo(); // ok, foo()…
aminfar
  • 2,297
  • 3
  • 27
  • 37
9
votes
5 answers

Binding temporary to a lvalue reference

I have the following code string three() { return "three"; } void mutate(string& ref) { } int main() { mutate(three()); return 0; } You can see I am passing three() to mutate method. This code compiles well. My understanding is,…
Navaneeth K N
  • 15,295
  • 38
  • 126
  • 184
9
votes
3 answers

When should I choose copy elision over passing argument by const reference?

Possible Duplicate: Is pass-by-value a reasonable default in C++11? I'm reading Want Speed? Pass by Value. by Dave Abrahams about copy elision and RVO. And I'm wondering why do we need the copy elision? I have been told too many times that you…
amazingjxq
  • 4,487
  • 7
  • 33
  • 35
8
votes
1 answer

Is a pointer an lvalue or rvalue?

In other post, I came across (5.2.9/8) An rvalue of type "pointer to member of D of type cv1 T" can be converted to an rvalue of type "pointer to member of B of type cv2 T", where B is a base class (clause 10) of D, Note this from language…
user1086635
  • 1,536
  • 2
  • 15
  • 21