C ++ 11标准库中的值和对象的示例? [英] C++11 example of a value and an object in the standard library?

查看:168
本文介绍了C ++ 11标准库中的值和对象的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ 11 3p3中,它指出:

In C++11 3p3 it states:


实体是值<对象,引用,函数,枚举器,类型,类成员,模板,模板专用化,命名空间,参数包或这一点。

An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this.

在17.6.1.1p1中,它声明:

In 17.6.1.1p1 it states:


C ++标准库为以下类型的实体提供定义:宏,,类型,模板,类,函数和对象

The C++ standard library provides definitions for the following types of entities: macros, values, types, templates, classes, functions, objects.

C ++标准库提供了一个不是一个对象的定义的示例,并且是一个对话:C ++标准库提供了一个不是值的定义的对象示例是什么?

What is an example of a value that the C++ standard library provides a definition for, that is not an object?, and conversly: What is an example of an object that the C++ standard library provides a definition for, that is not a value?

推荐答案

对象是存储在内存中的对象(参见1.8:对象是存储区域)。每个对象都有一个值(它本身),但值是更一般的,在每个表达式的赋值给出一个值的意义上。例如,对于声明的函数 T f(); ,例如的值可能有也可能没有存储–您不能获取其地址,并且其存在可能不需要显示为存储。 (但是,一旦将值绑定到引用变量或形式参数,现在可以通过名称引用对象。)

An object is something that is stored in memory (cf. 1.8: "An object is a region of storage"). Every object has a value (which is itself), but values are more general, in the sense that the evaluation of every expression gives a value. For example, a prvalue, such as the value of f() for a declared function T f();, may or may not have storage – you cannot take its address, and its existence may not need to be manifest as storage. (However, once you bind the value to a reference variable or formal parameter, you now have a way of referring to the object by name.)

区别主要是一个的语言语义,但通常不具有实际重要性。 (例如,人们常常引用临时对象,虽然临时值将更准确。)值和对象都有类型(它们始终是对象类型),可以评估对象以产生值,并且值可以被视为一个对象。在谈论代码设计,分配和存储时使用object,在谈论语言的语法规则时使用value。

The difference is mainly one of language semantics, though, and not usually of practical importance. (For example, people often refer to "temporary objects", although "temporary value" would be more accurate.) Values and objects both have types (which are always object types), an object can be evaluated to produce a value, and a value can be treated as an object. I would use "object" when talking about the code design, allocations and storage, and "value" when talking about grammatical rules of the language.

这篇关于C ++ 11标准库中的值和对象的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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