How to access object properties from within object method?
<p>I have this class named <code>Enemy</code> from which <code>Ninja</code> inherits its properties. In <code>Ninja</code>'s attack function, I'm trying to call <code>Ninja</code>'s <code>getAttackPower</code> function, but how do I get it. I tried calling <code>this.getAttackPower</code> but it didn't work.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;

using namespace std;

class Enemy {
    int attackPower;
    public:
        virtual void attack() { cout &lt;&lt; "I am attacking you!"; }
    protected:
        int getAttackPower() {
            return attackPower;
        }
        void setAttackPower( int a ) {
            attackPower = a;
        }
};

class Ninja : public Enemy {
    void attack() {
        cout &lt;&lt; "(minus " &lt;&lt; getAttackPower() &lt;&lt; " points).";
        // .................. right here ......
    }
};

int main() {
    Ninja ninjaObj;

    ninjaObj.setAttackPower(23);

    ninjaObj.getAttackPower();

}
</code></pre>

<p>Here are the errors I'm getting:</p>

<pre><code>void Enemy::setAttackPower(int) is protected
error: within this context
error: 'int Enemy::getAttackPower()' is protected
error: within this context
</code></pre>
