Class date{
protected:
int year_;
int month_;
int day_;
public:
date();
date(const int& d, const int& m, const int& y);
date operator++();    //prefix operator
date operator++(int); //postfix operator
date operator--();    //prefix operator
date operator--(int); //postfix operator
};

date date::operator++(int){  //postfix operator return current value
date d=*this;
*this=next_date(d);
return d;
}

date date::operator++(){     //prefix operator return new value
*this=next_date(*this);
return *this;
}

date date::operator--(int){  //postfix operator return current value 
date d=*this;
*this=previous_date(d);
return d;
}

date date::operator--(){     //prefix operator return new value
*this=previous_date(*this);
return *tprev
}

Here I omitted the functions previous date and next_date. But my question is what is the int in operator++(int) and operator--(int) mean? Is it just used to differentiate the other prefix operator or it really means something?

Thanks

Recommended Answers

All 2 Replies

>>what is the int in operator++(int)
It's just used to differentiate the two functions. It means nothing at all.

I'm not exactly sure what you are asking, but I can explain a couple things that you might be asking, as dumb as that sounds, lol.

operator++ would increase the date by one day and operator-- would decrease it.

also, the reason that there are prefix and postfix operators is because sometimes you want to increment the date before and sometimes you want to increment it after it's used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.