加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Glvalue真实的例子和解释?

发布时间:2020-12-16 09:55:29 所属栏目:百科 来源:网络整理
导读:我知道’xvalues’,’prvalues’,’rvalues’和’lvalues’是什么,它们是如何有用的,我已经看到了它们的真实例子.但我永远不会明白什么是’glvalue’,以及它如何与其他人合作.我到处搜索,但即使在最新的标准文件中也没有运气,几乎没有人注意到.有人可以向我
我知道’xvalues’,’prvalues’,’rvalues’和’lvalues’是什么,它们是如何有用的,我已经看到了它们的真实例子.但我永远不会明白什么是’glvalue’,以及它如何与其他人合作.我到处搜索,但即使在最新的标准文件中也没有运气,几乎没有人注意到.有人可以向我解释并展示一些例子吗?

请注意,这不是this的重复,因为即使没有人给出’glvalue’的例子.在这里too.它几乎没有像这样提到:

A glvalue (“generalized” lvalue) is an lvalue or an xvalue.

解决方法

glvalue是任何不是prvalue的东西.示例是实体的名称,或具有引用类型的表达式(无论引用的类型如何).

int i;
int* p = &i;
int& f();
int&& g();

int h();

h() // prvalue
g() // glvalue (xvalue)
f() // glvalue (lvalue)
i   // glvalue (lvalue)
*p  // glvalue (lvalue)

std::move(i)  // glvalue (xvalue)

正如您的问题中的引用明确指出的那样,glvalue类别包括所有xvalues和lvalues.左值,x值和prvalues是互补的类别:

Every expression belongs to exactly one of the fundamental
classifications in this taxonomy: lvalue,xvalue,or prvalue.

你应该熟悉左值.现在考虑xvalues是什么,[expr] / 6:

[ Note: An expression is an xvalue if it is:

  • the result of calling a function,whether implicitly or explicitly,whose return type is an rvalue reference to object type,
  • a cast to an rvalue reference to object type,
  • a class member access expression designating a non-static data member of non-reference type in which the object expression is an
    xvalue,or
  • a .* pointer-to-member expression in which the first operand is an xvalue and the second operand is a pointer to data member.

[…] — end note ]

因此,粗略地说,您可以将glvalues视为“所有左值加上涉及右值引用的表达式”.我们用它来描述引用对象而不是“存在”那些对象的表达式.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读