I'm trying to learn about inheritance, and now I'm having trouble accesing iherited variables.
unless I make all the Enemy class variables public, I can't seem to acces them from defiler. Could anyone tell me what the problem is?Code:#include <iostream>
using namespace std;
class Enemy
{
public:
Enemy(): hp(20), sp(0), flee(50), hit(50), atkPower(8) {};
void atk();
void takeDmg();
protected:
int hp;
int sp;
int flee;
int hit;
int atkPower;
};
class Defiler : public Enemy
{
public:
Defiler(){hp = 30, sp = 10, flee = 60, hit = 60, atkPower = 8;};
void defileAtk();
private:
int defileMultiply;
};
int main()
{
Defiler defOne;
cout << defOne.hp;
Enemy noOne;
cout << endl << noOne.hp;
cin.get();
return 0;
}