I'm creating a fraction class from scratch, and, in doing so, defining operator +,-,*,/ (and += etc). I already wrote the code for + and += and they work fine. I'm now trying to write -= by multiplying the second fraction by -1 and adding them. However, it must be written as a member function and I'm getting an error when trying to reference the calling object. This is what I tried:
1 2 3 4 5 6 7 8
void fraction::operator-=(const fraction& source)
{
fraction f1=source; // Local fraction, allowing us to manipulate source
f1.num *=-1;
this+=f1;
}
That gives me a compiler error, saying there is no operator that can take the fraction type (should be noted that I got that error before, and it was because tried to change the wrong item, a constant, so I'm not really sure how much sense it makes).