I need to overload the assignment/decrement operator (-=) so that the code
object -= int
decrements object.life class member by the value on the rhs. Here is my code:
const Object& Object::operator -= (const Object& obj)
{
if (life == obj.life)`
{
this->life -= obj.life;
return *this;
}
}
How do I implement this in my main?
int main()
{
Object o1;
o1 -= 5; //DOESN'T WORK
}
Any suggestions?
Thanks
You’re overloading the case when you subtract an object from an object, but the example you show is subtracting an integer. I you want to overload the operator that takes an integer: