c++ class inheritance, identifier undefined
<p>I'm new to object programming and to c++.</p>

<p>I'm applying what is taught in SoloLearn c++ course about class inheritance.</p>

<p>Class enemy: <strong>enemy.h</strong> </p>

<pre><code>class enemy
{
public:
    enemy();
    ~enemy();
    void setAttackPower();
protected:
    int aP;
};
</code></pre>

<p><strong>enemy.cpp</strong>:</p>

<pre><code>#include "enemy.h"
#include &lt;iostream&gt;
using namespace std;

enemy::enemy()
    {
        cout &lt;&lt; "constructor" &lt;&lt; endl;
    }
enemy::~enemy()
    {
        cout &lt;&lt; "destructor" &lt;&lt; endl;
    }

int aP=0;
void setAttackPower(int a) {
        aP = a;
    }
</code></pre>

<p>class ninja, that inherits from enemy:
<strong>ninja.h</strong>:</p>

<pre><code>#include "enemy.h"

class ninja: public enemy
{
public:
    ninja();
    ~ninja();
    void attack();
};
</code></pre>

<p><strong>ninja.cpp</strong>:</p>

<pre><code>#include "ninja.h"
#include &lt;iostream&gt;
using namespace std;

ninja::ninja()
{
}

ninja::~ninja()
{
}

void attack() {
    cout &lt;&lt; "Ninja attack " &lt;&lt; aP &lt;&lt; endl;
}
</code></pre>

<p>and the error is:</p>

<p>identifier "aP" is undefined. I can't see the problem. Can anyone help me?</p>