To preface this is homework and I'm not looking for answers, just a little direction because I can't make it to the lab tutor for help. My issue is that I've been given predefined class declarations that I can't change. I have 2 time objects that I need to add to equal a 3rd time object.
time3 = time2 + time1;
My overloaded function looks like this
Time Time :: operator + (const Time time2)
{
Time::addSeconds(time1.second);
Time::addMinutes(time1.minute);
Time::addHours(time1.hour); //changes hrs and days
return *this;
};
So I add in time1 and in my add functions I'm using the *this operator to assign which turns time2 into whatever time1 equals. So that doesn't work. I know how to do it if I could change my class definition, but I can't. I guess my intention was for *this to refer to time3, but it refers to the left hand side of the equation.
How can I make the result equal time3 in my add functions without changing the structure of my class?
I couldn't find any resources that show the proper way to handle this situation, but if you have any I'd be happy read through them.