Wrong return value when access member of class
I have a class Character and two subclasses Warrior and Wizard.
class Character {
protected:
std::string m_name;
Weapon m_weapon;
int m_life;
public:
virtual void hit(Character& cible);
};
class Warrior : public Character{
public:
Warrior(std::string name);
};
class Wizard : public Character{
public:
Wizard(std::string name);
};
I also have a class Weapon.
class Weapon {
protected:
std::string m_name;
int m_damage;
public:
Weapon();
Weapon(std::string name,int damage, int reloading_time);
int get_damage() ;
};
The hit function is:
void Character::hit(Character &cible){
cible.dec_life(m_weapon.get_damage());
}
and get_damage is simply:
int Weapon::get_damage() {
return m_damage;
}
The problem is that m_weapon.get_damage() returns the value -2 in the hit
function for every character (warrior or wizard).
Any idea where I get it wrong?
Thank You
No comments:
Post a Comment