<je**********@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
On Nov 11, 8:44 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
>On 2007-11-11 19:37:31 -0800, David Connet <con...@entelos.comsaid:
I don't know about .Net-land, but in native C++, the pre/post-increment
operators are 2 separate operators.
Yes, of course they are. Both the OP and I acknowledged that. And I
suppose if the OP is asking for how to declare such in C++, your post
would be relevant to that question (but not what I'd call on-topic in
this newsgroup).
I was curious about how it is done in C#. I am more than aware of how
to do it in C++.
C# doesn't have compound assignment operators (like +=, *=, ++). Instead,
it calls the base operator (+, *) and then the compiler generates the
assignment. Prefix and postfix are handled the same way (see section 7.5.9
of the standard). The operator++ implementation is NOT responsible for
changing the value in-place as it is in C++, rather the C# compiler assigns
the value returned from the operator++ implementation as a separate step.
"The run-time processing of a postfix increment or decrement operation of
the form x++ or x-- consists of the following steps:
· If x is classified as a variable:
o x is evaluated to produce the variable.
o The value of x is saved.
o The selected operator is invoked with the saved value of x as its
argument.
o The value returned by the operator is stored in the location given
by the evaluation of x.
o The saved value of x becomes the result of the operation.
· If x is classified as a property or indexer access:
o The instance expression (if x is not static) and the argument list
(if x is an indexer access) associated with x are evaluated, and the results
are used in the subsequent get and set accessor invocations.
o The get accessor of x is invoked and the returned value is saved.
o The selected operator is invoked with the saved value of x as its
argument.
o The set accessor of x is invoked with the value returned by the
operator as its value argument.
o The saved value of x becomes the result of the operation.
The ++ and -- operators also support prefix notation (§7.6.5). The result of
x++ or x-- is the value of x before the operation, whereas the result of ++x
or --x is the value of x after the operation. In either case, x itself has
the same value after the operation.
An operator ++ or operator -- implementation can be invoked using either
postfix or prefix notation. It is not possible to have separate operator
implementations for the two notations."
>
Thanks for your replies.