Sergey wrote:
Hmmm ... interesting concept, but creating new class instance may cause
serious
perfomance degrade. So it seems more safely to make new statement
instead of new instance. Why the worst case - temporary variable (new
instance) was choosed?
I am not sure how to answer your question. Perhaps Kernighan or Ritchie
answer it somehow in their writings on C language development. The
difference between prefix and postfix increment and decrement operators
exists in C++ from C, and in C probably from some other earlier language
(although I do not know if that's true or not).
The necessity to create (and return) a temporary object exists because
there seems to be no other way to both increment the object and return its
_previous value_ with post-increment, if you decide to follow the
semantics of post-increment defined for built-in types.
Both versions of increment or decrement operator are useful, if you think
about it. They both allow the compiler to generate optimized code. What
else is there, I don't know. But IMO that should be enough of a reason to
keep them in C++.
V