The result of the post-increment expression, a++
is an rvalue; a temporary with the value that a
had before incrementing. As an rvalue, you can use its value, but you can't modify it. Specifically, you can't apply pre-increment it, as the compiler says.
If you were to change the precedence to do the pre-increment first:
(++a)++
then this would compile: the result of pre-increment is an lvalue denoting the object that's been modified. However, this might have undefined behaviour; I'm not sure whether the two modifications and the various uses of the value are sequenced.
Summary: don't try to write tricky expressions with multiple side-effects.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…