Things got a little backed up - we're processing the data and things should be back to normal within the hour.

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
What are practical use cases for postfix increment / decrement operator?
Post Body

I know prefix operator doesn't store a copy it just modifies the instance but postfix operator stores a copy. Why? How come keeping a copy would be useful? What are the use cases? Here is a piece of code to illustrate my question.

#include <iostream>
#include <sstream>

class Int {
private:
    int x;
    std::string numberString;
public:
    Int(int _x):x(_x) {}
    Int operator   () {
      x  = 1;
      return *this;
    }
    Int operator   (int) {
      Int copy = *this;
        *this;
      return copy;
    }
    operator const char*() {
      std::ostringstream os;
      os << x;
      numberString = os.str();
      return numberString.c_str();
    }
};

int main() {
  Int a = 5;
  std::cout <<   a << std::endl; // 6
  Int b = a  ; // b is 6
  std::cout << b << std::endl; // 6
  std::cout << a << std::endl; // 7
}

Author
User Disabled
Account Strength
0%
Disabled 3 weeks ago
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
480
Link Karma
212
Comment Karma
268
Profile updated: 2 days ago
Posts updated: 3 weeks ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago