在 C++ 中,变量如何以及在何处可能没有关联的名称?

How and where is it possible that a variable does not has an associated name in C++?

在 C++17 标准中声明(强调我的):

"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."

Source: ISO/IEC 14882:2017 (C++17), §6/6 - "Basic concepts"

为什么是“if any”?变量可以在 C++ 中省略名称吗?

如果我查看 cppreference:

"In C++, a variable is actually just a bit of memory that has been reserved for the program’s use. You refer to it using a variable name, so you don’t need to worry about where it is in memory (though you can find out its memory address, and even specify its location, if you want)."

Source: https://en.cppreference.com/book/intro/variables

或维基百科(我知道它不是最好的来源但仍然很常见):

"In computer programming, a variable or scalar is a storage address (identified by a memory address) paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value. The variable name is the usual way to reference the stored value, in addition to referring to the variable itself, depending on the context."

Source: https://en.wikipedia.org/wiki/Variable_(computer_science)

这表示变量应始终提供与其相关联的名称,无论引用的 object/value 是否被它访问。


或者如果我误解了什么,那么“if any”如何解释?


相关:

What is the difference between a variable, object, and reference?

如评论中所述,

void foo(int) {}
//          ^

定义了一个没有名字的变量。

[basic.pre]/6:

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

这显然不是引用,但它是一个对象吗?是的

[intro.object]/1

An object is created by a definition, [...]

函数定义的参数是一个定义([basic.def]/2)。