C ++中的赋值运算符是返回右值还是左值? [英] Is assignment operator in c++ returns rvalue or lvalue?

查看:82
本文介绍了C ++中的赋值运算符是返回右值还是左值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的赋值运算符是否返回右值或左值?如果它是左值,那么这两个参数中的哪一个将在此处递增?

Is assignment operator in c++ returns rvalue or lvalue? And if it is lvalue, which of the two arguments will be incremented here?

(a = b)++

推荐答案

它返回左值.根据第5.17节:

It returns a lvalue. Per § 5.17:

赋值运算符(=)和复合赋值运算符全部从右到左分组.所有都需要一个可修改的左值操作数,并返回引用左侧操作数的左值.

The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand and return an lvalue referring to the left operand.

如果这些对象具有用户定义的运算符进行赋值,则取决于 operator = 的实现和声明(返回类型).

If those objects have an user-defined operator for assignment, then it depends on implementation and declaration (return type) of the operator=.

通常,之后

(a = b)++

对象 a 将增加.

这篇关于C ++中的赋值运算符是返回右值还是左值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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