问题
As the title suggests, this question has been asked before. However, the answers pertained to C++03/0x(11). C++11 (N3337) says this about variables:
[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 denotes the reference or object.
This may imply that variables are essentially named objects/references.
However, in C++14/C++17, that last sentence was changed to
The variable’s name, if any, denotes the reference or object.
which implies that a variable does not necessarily have a name.
A different interpretation of the first sentence may suggest that a variable is a name, since a name denoting an object/reference is also introduced by a declaration of such entities. But the second sentence contradicts that notion with the phrase "variable's name". So, is variable now just a hypernym for object and reference, whether named or not?
回答1:
This change was a result of CWG 1769, addressing the status of exception objects bound to unnamed catch handler parameters:
catch (std::exception&) // <==
{
}
That is now a variable. This simplifies the conceptual model around exception objects.
The first sentence, which remained unchanged, is still the complete definition of the term variable.
来源:https://stackoverflow.com/questions/51107333/follow-up-what-exactly-is-a-variable-in-c14-c17