Here is my code:
struct Goods {
int amount;
int rarity;
Goods operator -(const goods &other);
};
and this is how I attempt to implement operator- method:
Goods Goods::operator -(const Goods &other) {
this->amount = amount - other.amount;
this->rarity = rarity - other.rarity;
}
But this code doesn't work as intended. The actual value of this test
TEST(Mytest, GoodsMinus) {
Goods g1{3, 4};
Goods g2{2, 1};
ASSERT_EQ(1, (g1 - g2).amount);
ASSERT_EQ(3, (g1 - g2).rarity);
}
The actual value of first assert is 9435404, which is obviously wrong. What am I doing wrong here?