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
5
votes
3 answers

function template does not recognize lvalue

I have a problem in my code Here is simplified version of it : #include class A { public : template void func(T&&)//accept rvalue { std::cout<<"in rvalue\n"; } template void func(const…
uchar
  • 2,552
  • 4
  • 29
  • 50
5
votes
2 answers

Does "LValue" not mean what I think it means?

In the following code: _imageView.hasHorizontalScroller = YES; _imageView.hasVerticalScroller = YES; _imageView.autohidesScrollers = YES; NSLog(@"scrollbar? H %p V %p hide %p", &(_imageView.hasHorizontalScroller), …
Brian Postow
  • 11,709
  • 17
  • 81
  • 125
5
votes
1 answer

C error: lvalue required as unary '&' operand

I have a code error but not sure what's wrong with my casting and reference. BOOL xMBPortSerialPutByte( CHAR ucByte ) { CDC_Send_DATA(&((unsigned char)ucByte), 1); // code error here xMBPortEventPost(EV_FRAME_SENT); return TRUE; } The…
Shan
  • 323
  • 2
  • 6
  • 12
5
votes
5 answers

How there is Lvalue required error

There is a piece of code which is producing error of "Lvalue required". The code is as, #include #include #define max 10 int main() { printf("%d",max++); return 0; } It was evident that…
mrigendra
  • 1,472
  • 3
  • 19
  • 33
5
votes
1 answer

Can a function's return value be an lvalue in JavaScript?

Microsoft allows to set environment variables in JScript with the following syntax: var sh = WScript.CreateObject("Wscript.Shell"); var env = sh.Environment("PROCESS"); env("TEST") = "testvalue"; I wonder about the third line - and with me JSLint,…
rplantiko
  • 2,698
  • 1
  • 22
  • 21
5
votes
2 answers

"non-const lvalue reference to type cannot bind" error with reference (Type &) but not with pointer (Type *)

I am getting this error "Non-const lvalue to type 'Cell' cannot bind to a temporary of type 'Cell *' with this code : class RegionHolder { public: RegionHolder(Region& Region1):m_RegionCellNOO(&(Region1.m_NOO)) …
Alexis Cofion
  • 83
  • 1
  • 2
  • 5
5
votes
2 answers

Of what kind of lvalues can the address not be taken?

In this conference, Scott Meyers starts by saying "lvalues are generally expressions you can take the address of". I am stressing the word generally: what is an lvalue that you cannot take the address of? (if it exists). EDIT: Please provide code…
qdii
  • 12,505
  • 10
  • 59
  • 116
5
votes
2 answers

Is it legal to take the address of a const lvalue reference?

#include int foo() { return 0; } int main() { const int& a = foo(); std::cout << &a << std::endl; } In this code, a binds to a rvalue. Is it legal to take its address? (And by legal I mean: in the code ill-formed? Am I causing an…
qdii
  • 12,505
  • 10
  • 59
  • 116
4
votes
2 answers

Why doesn't make_pair() call the copy contructor, when given const string&?

Both GCC and Clang refuse to compile this one: #include #include using namespace std; int main() { const string s = "12345"; const string& r = s; auto p = std::make_pair(r, r); } GCC says: error:…
MWB
  • 11,740
  • 6
  • 46
  • 91
4
votes
1 answer

Why is move-constructor not called?

I have the following piece of code: #include struct T { int a; T() = default; T(T& other) { std::cout << "copy &\n"; } T(T&& other) { std::cout << "move &&\n"; } }; void foo(T&& x) { T…
mouse_00
  • 593
  • 3
  • 13
4
votes
2 answers

Is a variable that is about to go out of scope an lvalue or an xvalue?

When a variable that is about to go out of scope is returned or thrown, its resources can be reused i.e. it can be moved from, as the following C++ program shows: #include struct X { X() { std::cout << "X()\n"; } …
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67
4
votes
2 answers

C++ std::is_integral on lvalue and rvalue shows different results

I created a type validator to check whether a given argument is numeric. template struct is_numeric : std::integral_constant< bool, std::is_integral_v || std::is_floating_point_v > {}; template
PHD
  • 595
  • 1
  • 8
  • 18
4
votes
3 answers

Casting a pointer as lvalue

Why (int*) p = &x; is not a valid statement? while *(int*) p = &x; is valid statement with no warnings? I know that casting is rvalue, but how the second statement was compiled with no warnings?
4
votes
2 answers

Can a member function returns a modifiable lvalue reference to an rvalue object?

I have a bit confusion about this code: struct A { A& bar()&&; }; A& A::bar()&& { std::cout << "A::bar()&&\n"; return *this; } int main() { A{}.bar();// called by an rvalue } So what I understand is that bar can be called only by…
Maestro
  • 2,512
  • 9
  • 24
4
votes
2 answers

Const and reference member function qualifiers

Let's say we have member class with two member functions defined as follows: class SomeClass { private: int val = {}; public: const int getVarLRef() & { return val; } const int getVarCLRef() const& { return val; } }; int…
toozyfuzzy
  • 1,080
  • 1
  • 9
  • 20