c ++ styleguide:为什么在左侧有非左值? [英] c++ styleguide: why to have non-lvalues on the left side?

查看:96
本文介绍了c ++ styleguide:为什么在左侧有非左值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个 C ++编码风格指南中,
我发现了一个特别的建议(第41页,建议53):


左侧始终有非左值( 0 ==



$ b <$ p>我不知道这是什么好?是否坚持这种做法?



我不是,我不知道他为什么是一个好的做法。我可以想到的唯一的优势是,将避免错误的比较( if(foo = 0){} 对比 if你有什么其他想法为什么我应该使用它吗?



解决方案

是的,你猜对了。这是好的,老的 Yoda条件 !!!




In one C++ coding style guide, I found one particular recommendation (page 41, recommendation number 53):

Always have non-lvalues on the left side (0 == i instead of i == 0).

And I don't uderstand what is this good for? Are to sticking to this practice?

I'm not and I don't know why is his a good practice. The only advantage I can think of is that is will avoid mistaking an unintentional assignment with a comparison (if (foo = 0){} versus if (foo == 0){})

Have you got any other ideas why should I use it?

解决方案

Yes, you guessed it right. It's the good, old Yoda condition!!!

这篇关于c ++ styleguide:为什么在左侧有非左值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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