C ++中+ =和= +之间的区别 [英] Difference between += and =+ in C++

查看:233
本文介绍了C ++中+ =和= +之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用C ++编程时,我经常混淆"+ ="和"= +",前者实际上是我的意思. Visual Studio似乎接受两者,但是它们的行为有所不同,并且是我很多bug的来源.我知道a + = b在语义上等同于a = a + b,但是"= +"的作用是什么?

While programming in C++, I often confuse both "+=" and "=+", the former being the operator I actually mean. Visual Studio seems to accept both, yet they behave differently and is a source for a lot of my bugs. I know that a += b is semantically equivalent to a = a+b, but what does "=+" do?

推荐答案

=+确实是= +(赋值和一元+运算符).

=+ is really = + (assignment and the unary + operators).

为了帮助您记住+=,请记住它先进行加法运算,然后进行赋值运算.当然,这取决于实际的实现,但是应该用于原语.

In order to help you remember +=, remember that it does addition first, then assignment. Of course that depends on the actual implementation, but it should be for the primitives.

这篇关于C ++中+ =和= +之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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