I have written a Date class and Im trying to practice operator overloading on this class. I have tried to overload the operator++
to increment the day by one, but i still get this error: cannot increment value of type 'Date'!
here is my method for overloading this operator:
Date Date::operator++()
{
day++;
if (day > days_of_month(month, year)) {
day = 1;
month++;
if (month > 12) {
month = 1;
year++;
}
}
return *this;
}
and this is the days_of_month
method:
int days_of_month(int m, int y)
{
if (m < 7)
return 31;
else if (m < 12)
return 30;
else if (m == 12)
return is_leap_year(y) ? 30 : 29;
else
abort();
}