I have the following code to overload the + and += operators respectively for the class Date. The operator + was successfully overloaded, and it will take an integer n and increase Date objects by n days. This is done by applying the next_day function n times.
inline Date operator+(Date d, int n)
{
for(char j=1; j<=n; j++){
d=d.next_day(d);
}
return d;
}
inline Date operator+=(Date d, int n)
{
Date p=d+n;
return p;
}
Having overloaded the + operator, I'm using it to define the overloading of += as well. But although no errors occurred in compilation, when I use the overloaded += it doesn't seem to have any effect.
Here's my main.cpp:
#include <iostream>
#include "Date.h"
using namespace std;
int main() {
Date Initialday = Date (12,1,2012);
Initialday+=1;
cout <<"Next day = "<< Initialday <<endl;
return 0;
}
Running the main function still gives me 12/1/2012 instead of 12/2/2012. What am I doing wrong? Note: I've already overloaded << to output Date objects in a readable format, so I don't think that's the issue.