c++ - Why implement postincrement in terms of preincrement? -


Herb Sutter suggests to apply such incremental increments:

  TT :: operator ++ (int) () {auto-old = * this; // Remember our original value ++ * this; // Always applies the post incr to the case of the old withdrawal; // our original value comes back}   

with the guideline:

Guidelines : for continuity, always the term According to Preincrement, otherwise your users will get amazing (and often unpleasant) results.

What are these amazing (and often unpleasant) outcomes?

This ensures that two operators will behave equally how they modify the objects, and Only their returns are different in values. If you apply two operators separately, and you decide to modify one of them, then you can forget to make the equivalent of the other. If you apply one to another in the case of another, then you have to make a change to only one place. And it makes sense for a more radical one, because the only difference in backwardness is to save the old value temporarily beforehand.

He might have escalated things when he said that your users get amazing results perhaps they have said that can get amazing results , because This will only happen if you are confused.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -