Can't access protected int variable of the pointer Parent class : <p>I have a question about protected variables. Maybe i didn't really understand them but isnt the reason to use them, that child classes can use them? Overall i want to decrease the lifepoints.</p>

<p>Here is my code:
Header file</p>

<pre><code>class Fighter {
protected:
    int offensePoints;
    int defensePoints;
    int lifepoints;
    std::string name;
public:
    Fighter(const std::string n);
    virtual ~Fighter();
    virtual void attackFighter(Fighter * f);
    int randomval(int min, int max);
    bool isalive();
    void isattacked(Fighter * at, int dmg);
};

class Warrior : public Fighter
{
public:
    Warrior(const std::string n);
    virtual ~Warrior();
    void attackFighter(Fighter * f);
    int randomval(int min, int max);
    bool isalive();
    void isattacked(Fighter * at, int dmg);
};
</code></pre>

<p>Class Fighter:</p>

<pre><code>void Fighter::attackFighter(Fighter * f)
{
    if (isalive())
    {
        f-&gt;lifepoints -= randomval(0, offensePoints);
    }
}
</code></pre>

<p>Class Warrior</p>

<pre><code>void Warrior::attackFighter(Fighter * f)
{
    if (isalive())
    {
        f-&gt;lifepoints -= randomval(0, offensePoints);
    }
}
</code></pre>
