不是完整表达式的语句 [英] Statement that isn't a full-expression

查看:89
本文介绍了不是完整表达式的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经常听到在C ++中,临时对象在 full-expression 的末尾被解构. full-expression 被定义为不是某些其他表达式的子表达式的表达式.这听起来与我的声明的概念非常相似.

It is often heard that in C++ temporary objects get deconstructed at the end of the full-expression. A full-expression is defined to be an expression that isn't a sub-expression of some other expression. This sounds very similar to the notion of a statement to me.

所以我的问题是:如果我在 full-expression 后面加上分号,它将始终是声明吗?可以通过在结尾加上分号的陈述并删除该分号来得出每个 full-expression .我可以假设每个临时文件都可以保留到其声明结束时吗?

So my questions are: If I append a semi-colon to a full-expression, will it always be a statement? Can one arrive at every full-expression by taking some statement with a semi-colon at the end, and removing that semi-colon? Can I assume that every temporary will live until the end of its statement?

推荐答案

下面的语句长于所包含临时变量的生存期:

Here's a statement that is longer than the lifetime of a contained temporary:

if (T() == T())
  foo();

condition 中的表达式创建的两个临时变量在完整表达式的末尾被销毁,并且当 statement ( foo(); )执行.

The two temporaries created by the expression in the condition are destroyed at the end of the full-expression and are no longer alive when the statement (foo();) executes.

请注意,对于任何表达式 e e ; 是一个语句(即 expression语句,请参见[stmt.expr]).

Note that for any expression e, e; is a statement (namely an expression statement, see [stmt.expr]).

这篇关于不是完整表达式的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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