I am a novice to C++ and having the following issue:
I have a parent class, called Creature:
class Creature
{
public:
bool isActive;
std::string name;
int attackNumOfDice, attackNumOfSides,
defenseNumOfDice, defenseNumOfSides;
int armor, strength;
Creature();
//two virtual functions determine the damage points
virtual int attack();
virtual int defend();
void halveAttackDice();
void setStrength(int toSet);
void setStatus(bool activity);
};
and 5 child classes like so:
.h file:
class Child : public Creature
{
int attack();
int defend();
}
implementation file:
int Child::isActive = true;
std::string Child::name = "";
int Child::attackNumOfDice = 2;
...
int Child::attack()
{
...
}
intChild::defend()
{
...}
however, when I try to compile like this I get the same error for all 5 child classes:
child.cpp:6: error: ‘bool Child::isActive’ is not a static member of ‘class Child’
child.cpp:7: error: ‘std::string Child::name’ is not a static member of ‘class Child’
child.cpp:8: error: ‘int Child::attackNumOfDice’ is not a static member of ‘class Child’
...
I don't understand why is saying not a static member when I never defined one?