When do we get "l-value required" error...while compiling C++ program???(i am using VC++ )
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Try to compile:
and you get
error: lvalue required as left operand of assignment
An "lvalue" is a value that can be the target of an assignment. The "l" stands for "left", as in the left hand side of the equals sign. An rvalue is the right hand value and produces a value, and cannot be assigned to directly. If you are getting "lvalue required" you have an expression that produces an rvalue when an lvalue is required.
For example, a constant is an rvalue but not an lvalue. So:
doesn't work, but:
Does. Note that you can return an lvalue from a function; for example, you can return a reference to an object that provides a operator=().
As pointed out by Pavel Minaev in comments, this is not a formal definition of lvalues and rvalues in the language, but attempts to give a description to someone confused about an error about using an rvalue where an lvalue is required. C++ is a language with many details; if you want to get formal you should consult a formal reference.
I had a similar issue and I found that the problem was I used a single '=' instead of a double '==' in an if statement
lvalue error:
correct:
This happens when you're trying to assign to something (such as the result of a scalar function) that you can't assign to.
This happen when you try manipulate the value of a constant may it be increments or decrements which is not allowed. `
We assign value to a variable. If we try to do the reverse thing then L-value errors occur.