简体   繁体   English

表达式作为在 C++ 中调用 function 的结果

[英]expression as the result of calling a function in C++

How does result of function call can be an expression? function 调用的结果如何是表达式? I am reading this article - http://eel.is/c++draft/expr and it is written there that我正在阅读这篇文章 - http://eel.is/c++draft/expr并写在那里

An expression is an xvalue if it is the result of calling a function, whether implicitly or explicitly, whose return type is an rvalue reference to object type如果表达式是调用 function(无论是隐式还是显式)的结果,则表达式是一个 xvalue,其返回类型是对 object 类型的右值引用

I don't understand how does an expression can be a result of function call.我不明白表达式如何成为 function 调用的结果。

Consider these two examples.考虑这两个例子。

const auto someValue = 43 * otherValue;
const auto someOther = func();

In both cases, the right hand side of the assignent is an expression.在这两种情况下,赋值的右侧都是一个表达式。 In the first case, it's an integer multiplication.在第一种情况下,它是 integer 乘法。 In the second call, it's a function call.在第二个调用中,它是一个 function 调用。 Let's be as clear as possible: the expression is not the result of calling a function -- instead, func() is an expression.让我们尽可能清楚:表达式不是调用 function 的结果——相反, func()一个表达式。

Let's imagine the signature of this function call is假设这个 function 调用的签名是

struct Obj { /* ... */ };

Obj&& func();

Here, the return type is an rvalue reference of object type.这里,返回类型是 object 类型的右值引用。 This is meant by the wording in the standard.这是标准中的措辞所表示的。 And in the above case, the expression func() is an xvalue (an "eXpiring value").在上述情况下,表达式func()是一个xvalue (一个“eXpiring 值”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM