- Code: Select all
RacingData RacingData::operator+(RacingData &other)const
{
string dummyString;
int otherScore, otherMinutes, otherSeconds;
RacingData newObject;
other.getData(dummyString, otherScore, otherMinutes, otherSeconds);
newObject.setData(name, score + otherScore, minutes + otherMinutes, seconds + otherSeconds);
// We now need to make sure that the totals make sense. If seconds > 59, we want to roll over another minute.
newObject.getData(dummyString, otherScore, otherMinutes, otherSeconds);
if (otherSeconds > 59)
{
otherMinutes = otherMinutes + (otherSeconds / 60);
otherSeconds = otherSeconds % 60;
newObject.setData(name, otherScore, otherMinutes, otherSeconds);
}
return newObject;
}
was right. All that I was missing and it made the whole thing work is by using the this-> pointer in the set and get functions.
- Code: Select all
void RacingData::setData(string n, int S, int m, int s)
{
this->name = n;
this->score = S;
this->minutes = m;
this->seconds = s;
}
void RacingData::getData(string& name, int& score, int& minutes, int& seconds)const
{
name = this->name;
score = this->score;
minutes = this->minutes;
seconds = this->seconds;
}
I was going insane for just this-> D:

