Sukhanov Niсkolay
Sukhanov Niсkolay

Reputation: 1328

Does an assignment operator in c++ return rvalue or lvalue?

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

(a = b)++

Upvotes: 7

Views: 1228

Answers (1)

masoud
masoud

Reputation: 56479

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.

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

So normally, after

(a = b)++

The object a will be incremented.

Upvotes: 11

Related Questions