是否保证在C ++中的短路评估,因为它是在Java? [英] Is Short Circuit Evaluation guaranteed In C++ as it is in Java?

查看:124
本文介绍了是否保证在C ++中的短路评估,因为它是在Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,我使用

if (a != null && a.fun());

从左向右计算?

在C ++中,我可以这样做吗?他们是否保证在不同的平台和编译器之间移植?

In C++, can I do the same? Are they guarantee to portable across different platform and compiler?

if (a != 0 && a->fun());


推荐答案

类型。但是,如果你超载&&或||对于您自己的类型,不执行短路评估。因此,重载这些操作符被认为是一件坏事。

Yes, it is guaranteed for the "built in" types. However, if you overload && or || for your own types, short-circuited evaluation is NOT performed. For this reason, overloading these operators is considered to be a bad thing.

这篇关于是否保证在C ++中的短路评估,因为它是在Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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