often used seldom defined terms: lvalue

后端 未结 8 1779
南旧
南旧 2020-11-27 17:25

What is an lvalue?

8条回答
  •  隐瞒了意图╮
    2020-11-27 18:25

    One of the best explanations I know of can be found in this article on RValue references.

    another way to determine whether an expression is an lvalue is to ask "can I take its address?". If you can, it's an lvalue. If you can't, it's an rvalue. For example, &obj , &*ptr , &ptr[index] , and &++x are all valid (even though some of those expressions are silly), while &1729 , &(x + y) , &std::string("meow") , and &x++ are all invalid. Why does this work? The address-of operator requires that its "operand shall be an lvalue" (C++03 5.3.1/2). Why does it require that? Taking the address of a persistent object is fine, but taking the address of a temporary would be extremely dangerous, because temporaries evaporate quickly.

提交回复
热议问题