I have an object "d" of type Date. I am trying to use an overloading operator to take in only one parameter from the user instead of the three that the objects has. In other words, I want the program to be able to take input from the user and be able to only change the "month_" data member and then having that data member be passed to the "incMon()" so that the month and the year adjust accordingly to however many months the user wants to increment the date using only the "month_" data member.
How can I adjust the overloading operator and incMon() to allow this process to happen?
This is what I have.
void Date::read(istream & is)
{
unsigned month;
is >> month;
month_ = month;
}
istream & operator>>(istream & is, Date & d)
{
d.read(is);
return is;
}
I'm interpreting the original question as: "How to make the given main function work?"
Minimal intrusive way, would be
istream & operator>>(istream & is, Date & d)
{
int num = 0;
is >> num;
d.incrementMonth(d, num);
return is;
}
Although I want to stress, that this solution results in rather unexpected code (reading an object vs reading an int to increment).