“身份"的含义是什么?在C ++中的值类别的定义中 [英] What's the meaning of "identity" in the definition of value categories in C++

查看:122
本文介绍了“身份"的含义是什么?在C ++中的值类别的定义中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,您可以回答有关身份的部分,谢谢.这个问题的主要重点是从2开始.关于身份,我只是想提供我目前的理解的背景信息/背景,因此它可能有助于您在编写答案时确定深度.

In short, you can just answer the part about identity, thanks. My main focus of this question is start from 2. about identity, I just tried to provide context/background of my current understanding so it may help you decide the depth when you're writing your answer.

我想了解C ++中类型系统和值类别的概况.我已经在网上搜索/阅读了许多问题和资源,但是每个人都有独特的解释,所以我真的很困惑.如果有人可以提供有关以下内容的信息,我将列出我无法掌握的部分

I want to understand the big picture of type system and value categories in C++. I've searched/read many questions and resources online, but everyone has a distinct explanation, so I'm really confused. I'll list the part I can't grasp, if anyone could provide idea about

  1. cppreference.com的第一行:

对象,引用,函数 ,包括 函数模板专业化 表达式 具有一个名为type的属性,该属性不仅限制了这些实体所允许的操作,而且还为其他通用位序列提供了语义.

Objects, references, functions including function template specializations, and expressions have a property called type, which both restricts the operations that are permitted for those entities and provides semantic meaning to the otherwise generic sequences of bits.

我的问题:

  • 表达式具有类型是什么意思?是评估后最终结果的类型吗?
  • 我现在不想学习模板,这会妨碍对基本部分的学习吗(从您的专家的角度来看)?我花了一些时间才意识到转发引用和右值引用是不同的东西,前者是用于模板的.

值类别:

我阅读了的答案-什么是右值,左值,x值,glvalue和prvalue?,这句话很麻烦我很多是 身份 ,它也出现在

I read this answer of - What are rvalues, lvalues, xvalues, glvalues, and prvalues?, the phrase bother me a lot is identity, which also appears on cppreference.com - Value categories (Line 5, glvalue).

我的问题:我可以说identity ==我可以为其分配新值的所有内容吗?

my question: can I say that identity == everything I can assign a new value on it?

  • I saw people using the word address/pointer for it, but is that has identity iff has address/pointer? I want the precise term.
  • I came across the idea of bit-field when reading cppreference.com, it seems like given a bit-field struct a, its bit field a.m has no address? Is this the reason the word identity is used instead of address/pointer?
  • I found a blog post explaining this, but it's lvalue definition is counter-intuitive: an lvalue denotes an object whose resource cannot be reused, why not?

推荐答案

  1. 表达式的类型是,如果以及何时对表达式求值,其结果将具有的类型.表达式没有必须进行求值,但是所有表达式都具有类型.类型是静态属性.
  2. 没有确切的身份定义,也没有迹象表明哪些实体具有或没有身份.这是一个泥泞的概念,最好不去管它.忽略它.有人说对象标识是它的地址,但是这个概念是没有用的.那为什么不只是谈论它的地址呢?那位域呢?它们是没有地址的对象,它们没有身份吗?其他人说左值具有身份,右值不具有身份,但是那样就多余了.
  1. The type of an expression is the type its result would have, if and when the expression were evaluated. An expression doesn't have to be evaluated, but all expressions have type. Type is a static property.
  2. There's no precise definition of identity, or an indication of which entities do or do not have identity. It's a muddy concept that is better left alone. Ignore it. Some people say that object identity is its address, but then this concept is useless. Why not just talk about its address then? And what about bit fields? They are objects without addresses, don't they have identity? Others say that lvalues have identity and rvalues don't, but then it's just as redundant.

这篇关于“身份"的含义是什么?在C ++中的值类别的定义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆