New to this kind of stuff, probably doing something wrong, but -
I have 3 members
std::unique_ptr<Gun> currentWeapon;
std::unique_ptr<Gun> weaponSlotOne;
std::unique_ptr<Gun> weaponSlotTwo;
Gun is a base class that has other derived classes such as Pistol
and SMG
.
What i'm doing is setting weaponSlotOne
and weaponSlotTwo
to two different guns, then setting currentWeapon
to the first weapon.
weaponSlotOne.reset(new DevPistol());
weaponSlotTwo.reset(new AutoDevPistol());
currentWeapon = std::move(weaponSlotOne);
and i have a switchWeapons
method, that does this:
void Player::switchWeapons() {
if(currentWeapon == weaponSlotOne) {
currentWeapon = std::move(weaponSlotTwo);
}
else {
currentWeapon = std::move(weaponSlotOne);
}
}
which seems to destroy/deallocate both guns for some reason. i'm not quite sure what's going wrong.