“变量"的定义是什么? [英] What is the definition of a "variable"?

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

问题描述

标准指出

实体是值,对象,引用,函数,枚举数,类型,类成员,模板,模板专业化,名称空间,参数包装或这个.

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

这意味着变量" 不是实体.

但在标准中进一步说:

每个表示实体的名称都由声明引入.每个表示标签的名称都由goto引入陈述(6.6.4)或标记陈述(6.1).

Every name that denotes an entity is introduced by a declaration. Every name that denotes a label is introduced either by a goto statement (6.6.4) or a labeled-statement (6.1).

通过引用以外的引用的声明来引入变量非静态数据成员或对象.变量名称表示引用或对象.

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object.

我从这两个引号中假设变量是一个名称.

I'm assume from this two quotes that a variable is a name.

这是因为变量是由引用声明引入的,每个表示实体的名称都是由声明引入的.但是变量的名称是什么意思?根据定义,变量也是一个名称.

It is because the variable is introduced by declaration of reference and every name that denotes entity introduced by a declaration. But what does a variable's name mean? A variable is also a name by definition.

推荐答案

术语变量的定义在这方面有点含糊,但是通过查看c ++标准中术语变量的各种用法,它看起来像变量是一种特殊的实体.它可以是对象,也可以是引用.但是,并非所有对象或引用都是变量,只有 [basic]/6 中所述的那些对象或引用:

The definition of the term variable is a bit ambiguous in this respect, but by looking at the various uses of the term variable in the c++ standard, it looks like a variable is a special kind of entity. It is either an object or a reference. However, not all objects or references are variables, only the ones introduced the way described in [basic]/6:

通过引用以外的引用的声明来引入变量非静态数据成员或对象.变量的名称(如果有),表示参考或对象.

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable's name, if any, denotes the reference or object.

请注意,某些变量未命名,例如下面的示例中的函数f的参数:

Note that some variables are unnamed, for example the parameter of the function f in the example below:

void f(int) {}

int main() {}

这篇关于“变量"的定义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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