mardi 29 décembre 2020

Why are functions returning references with prefix inc/dec operators are lvalue expressions but not with postfix inc/dec operators

Why functions that return lvalue references, along with prefix increment/decrement operators are lvalue expressions whereas, functions that return lvalue references along with postfix increment/decrement operators are not lvalue expressions ?

C++ Primer, Lippman et al. 5/e mentions :

Functions that return lvalue references, along with the assignment, subscript, dereference, and prefix increment/decrement operators, are all examples of expressions that return lvalues. We can bind an lvalue reference to the result of any of these expressions.

Functions that return a nonreference type, along with the arithmetic, relational, bitwise, and postfix increment/decrement operators, all yield rvalues. We cannot bind an lvalue reference to these expressions, but we can bind either an lvalue reference to const or an rvalue reference to such expressions.*

Aucun commentaire:

Enregistrer un commentaire