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
13
votes
8 answers

Casting a pointer does not produce an lvalue. Why?

After posting one of my most controversial answers here, I dare to ask a few questions and eventually fill some gaps in my knowledge. Why isn't an expression of the kind ((type_t *) x) considered a valid lvalue, assuming that x itself is a pointer…
Blagovest Buyukliev
  • 42,498
  • 14
  • 94
  • 130
13
votes
3 answers

"expression must be an l-value or function designator" error when taking the address of this

I'm trying to do this in C++: class Abc { int callFunction1() }; void function1(Abc** c1) {//do something} int Abc::callFunction1() { function1(&this); return 0; } And I get "expression must be an l-value or function designator" error in…
disccip
  • 573
  • 3
  • 5
  • 15
13
votes
2 answers

C++0x: rvalue reference versus non-const lvalue

When programming in C++03, we can't pass an unnamed temporary T() to a function void foo(T&);. The usual solution is to give the temporary a name, and then pass it like: T v; foo(v); Now, along comes C++0x - and now with rvalue references, a…
Channel72
  • 24,139
  • 32
  • 108
  • 180
13
votes
4 answers

Array and Rvalue

$4.2/1 - "An lvalue or rvalue of type “array ofN T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array." I am not sure how do we get an rvalue…
Chubsdad
  • 24,777
  • 4
  • 73
  • 129
13
votes
2 answers

How to access an object's storage through an aggregate

In "Lvalues and rvalues", [basic.lval] (3.10), the C++ standard contains a list of types such that it is valid to "access the stored value of an object" through a glvalue of such a type (paragraph 10). Specifically, it says: If a program attempts…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
13
votes
3 answers

Pass lvalue to rvalue

I made a small 'blocking queue' class. It irritates me that I have created redundant code for values passed into the enqueue member function. Here are the two functions that do the same exact thing (except the rvalue uses std::move to move the…
TheAJ
  • 10,485
  • 11
  • 38
  • 57
12
votes
2 answers

Why is an enum variable an rvalue here?

Example: typedef enum Color { RED, GREEN, BLUE } Color; void func(unsigned int& num) { num++; } int main() { Color clr = RED; func(clr); return 0; } I get the following error when I compile this: : In function…
Koen
  • 311
  • 2
  • 11
12
votes
4 answers

In C language, is it semantically possible to create an lvalue with incomplete type?

In the C89 standard, I found the following section: 3.2.2.1 Lvalues and function designators Except when it is the operand of the sizeof operator, the unary & operator, the ++ operator, the -- operator, or the left operand of the . operator or an…
12
votes
1 answer

Can an lvalue reference non-type template parameter be inferred?

I have the following code, which I cannot get to work: struct foo {}; foo foo1 = {}; template class FooClass {}; template void foobar(FooClass arg) { } int main() { FooClass f; foobar(f); } The error…
molf
  • 73,644
  • 13
  • 135
  • 118
12
votes
2 answers

C++11: Is using std::move only safe on temporary objects?

In my code, I have something like this: unordered_multimap > mEntities; ... vector > rawEntities; if (qi::phrase_parse(&buf[0], (&buf[0]) + buf.size(), EntityParser(),…
bombax
  • 1,189
  • 8
  • 26
12
votes
1 answer

Passing rvalue reference to const lvalue reference paremeter

I am trying to understand C++11 rvalue references and how to use them for optimal performance in my code. Let's say we have a class A that has a member pointer to a large amount of dynamically allocated data. Furthermore, a method foo(const A& a)…
Sven
  • 143
  • 1
  • 1
  • 7
12
votes
1 answer

Understanding template argument deduction with rvalue/lvalue

This is a followup from function template does not recognize lvalue Lets play with the following code: #include template void func(T&&) { std::cout<<"in rvalue\n"; } template void func(const T&) { std::cout<<"in…
hivert
  • 10,579
  • 3
  • 31
  • 56
11
votes
4 answers

Is there a reason why an array name is not an lvalue?

For example, int x[10]; int i = 0; x = &i; //error occurs! According to C - A Reference Manual, an array name cannot be an lvalue. Thus, x cannot be an lvalue. But, what is the reason the array name cannot be an lvalue? For example, why does an…
Jin
  • 1,902
  • 3
  • 15
  • 26
10
votes
4 answers

One VS2010 bug ? Allowing binding non-const reference to rvalue WITHOUT EVEN a warning?

string foo() { return "hello"; } int main() { //below should be illegal for binding a non-const (lvalue) reference to a rvalue string& tem = foo(); //below should be the correct one as only const reference can be bind to…
RoundPi
  • 5,819
  • 7
  • 49
  • 75
10
votes
1 answer

Why is my code printing rvalue 2 times instead of rvalue & lvalue?

So I wanted to practice the usage of std::forward and created a Test class with 2 constructors. 1 with T& and the other with T&& as overload. T& prints lvalue, and T&& prints rvalue so I know which one of the constructors is being used. I create 2…
3l4x
  • 103
  • 4