class Date{
private:
int _day, _month, _year;
....
public:
Date& operator ++();
Date operator ++(int);
.....
};
/*
* Overloads the ++ postfix operator.
* Increments the day by 1.
*/
Date Date::operator ++(int u){
Date tmp=Date(*this);
_day++;
correct();
return tmp;
}
/*
* Overloads the ++ prefix operator.
* Increments the day by 1.
*/
Date& Date::operator ++(){
++_day;
correct();
return *this;
}
int main()
{
int d1,m1,y1,d2,m2,y2;
cin>>d1>>m1>>y1>>d2>>m2>>y2;
Date first=Date(d1,m1,y1);
Date second=Date(d2,m2,y2);
first++.print();
++first.print();
second.print();
return 0;
}
The third to last line in main() (line 38) throws an error:
error: no pre-increment operatorfor type
Just a side note, the correct() method simply fixes the date so that the day/month/year is correct (not too many days in a month, months in a year...).
Also you can assume that the copy constructor works properly (I tested it).
I'm not sure if it's relevant, but I'm using GCC version 4.4.3