Help, Overloading Operators

Re: Help, Overloading Operators

Post by Neccross on Mon Oct 11, 2010 10:12 pm
([msg=47408]see Re: Help, Overloading Operators[/msg])

Well apparently the code
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:
New User
New User
Posts: 21
Joined: Tue Jun 03, 2008 3:34 pm
Location: California
Blog: View Blog (0)


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests