Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;11:literal 7是一个prvalue?_C++_C++11 - Fatal编程技术网

C++ C++;11:literal 7是一个prvalue?

C++ C++;11:literal 7是一个prvalue?,c++,c++11,C++,C++11,我遇到了这个。它的例子是: int main() { int i, j, *p; // Correct usage: the variable i is an lvalue and the literal 7 is a prvalue. i = 7; ... } 我想知道为什么文字7是prvalue 标准[7.2.1.1.2]规定: A prvalue is an expression whose evaluation initializes an object or

我遇到了这个。它的例子是:

int main()
{
    int i, j, *p;

    // Correct usage: the variable i is an lvalue and the literal 7 is a prvalue.
    i = 7;
...
}
我想知道为什么文字7是prvalue

标准[7.2.1.1.2]规定:

A prvalue is an expression whose evaluation
initializes an object or a bit-field, or computes the value of an
operand of an operator, as specified by the context in which it
appears, or an expression that has type cv void.
表达式
7
本身不初始化对象或位字段,也不计算运算符操作数的值,因为
7
本身没有运算符

也许我没有正确解释标准

表达式
7
本身不会初始化对象或位字段

实际上,它初始化了
7
对象。看

prvalue 以下表达式是prvalue表达式:

  • 文本(字符串文本除外),例如
    42
    true
    nullptr

您使用的标准引号描述了prvalues的属性,但没有定义它们。这些定义分散在标准中(并被收集)

您的情况定义见:

字符串文字是左值,用户定义的文字与[lex.ext]中描述的相应运算符调用表达式具有相同的值类别,任何其他文字都是prvalue


7不是初始化了
i
?而且,你指的是有史以来最差的文档。7是一个
prvalue
,本节中明确提到了这一点article@d4rk4ng31是的。但是注释仅指表达式
7
,而不是
i=7。例如,我们不会在
i=j中说表达式
j
肯定是prvalue,对吗?j不是左值吗?因为它有一个标识?@HCSF i=j中的表达式j;LValy是“如果实体是[……]变量,表达式是一个LValk”,C++标准中的“代码>对象< /代码>的定义是什么?我一直认为它指的是非文字的东西。这些例子没有提到任何关于文字的东西。谢谢你的链接。这篇文章与
int
变量相关,与
7
不同。juanchopanza在评论部分指出了答案中的一些谬误。事实上,关于这个问题的其他答案提供了更多细节,更重要的是,还提供了关于这个问题的更多正式文件的链接。