lvalue to rvalue implicit conversion

前端 未结 2 1027
既然无缘
既然无缘 2020-11-28 23:07

I see the term \"lvalue-to-rvalue conversion\" used in many places throughout the C++ standard. This kind of conversion is often done implicitly, as far as I can tell.

2条回答
  •  失恋的感觉
    2020-11-28 23:50

    On glvalues: A glvalue ("generalized" lvalue) is an expression that is either an lvalue or an xvalue. A glvalue may be implicitly converted to prvalue with lvalue-to-rvalue, array-to-pointer, or function-to-pointer implicit conversion.

    Lvalue transformations are applied when lvalue argument (e.g. reference to an object) is used in context where rvalue (e.g. a number) is expected.

    Lvalue to rvalue conversion
    A glvalue of any non-function, non-array type T can be implicitly converted to prvalue of the same type. If T is a non-class type, this conversion also removes cv-qualifiers. Unless encountered in unevaluated context (in an operand of sizeof, typeid, noexcept, or decltype), this conversion effectively copy-constructs a temporary object of type T using the original glvalue as the constructor argument, and that temporary object is returned as a prvalue. If the glvalue has the type std::nullptr_t, the resulting prvalue is the null pointer constant nullptr.

提交回复
热议问题