What is an example of a difference in allowed usage or behavior between an xvalue and a prvalue FOR NON-POD objects?

后端 未结 2 1578
时光说笑
时光说笑 2020-12-09 10:12

What are rvalues, lvalues, xvalues, glvalues, and prvalues? gives a good overview of the taxonomy of rvalues/lvalues, and one of the recent answers to that question (https:/

2条回答
  •  一整个雨季
    2020-12-09 10:46

    What is the true difference between an xvalue and a prvalue? The xvalue is a kind of rvalue that can be cv-qualified and refer to an object and have dynamic type equal or unequal the static type.

    const int&& foo();
    int&& _v=foo();
    

    Without xvalue, the return value of the above function foo can only be a rvalue. But build-in types have not const rvalue! Thus, the above non-const variable _v can always bind the return value of foo(), even we wish the foo() return a const rvalue.

提交回复
热议问题