So I am trying to learn factory methods, and I am using the game plants vs zombies for example. I am just trying to create 4 different types of zombies. Ive been looking online for quite a while and can't find or understand what the problem is with my code. I am getting the unimplemented pure virtual method error.
I am getting the error on takeDamage(). Why am I getting this error?
I have my main as empty for now trying to figure this out
here is my code
class Zombie
{
public:
static Zombie *make_zombie(int choice);
virtual void takeDamage(int d) = 0;
virtual ~Zombie() {};
//void die();
};
class Reg_Zombie : public Zombie
{
public:
int health = 50;
void takeDamage(int d)
{
health -= d;
cout << "The Regular Zombie has taken 25 damage!";
}
};
class Cone : public Zombie
{
public:
int health = 50;
int acc = 25;
void takeDamage(int d)
{
if (acc > 0)
{
acc -= d;
cout << "The Cone Zombie has taken 25 to the accesory!";
}
else{
health -= d;
cout << "The Cone Zombie has taken 25 damage to health!";
}
}
};
class Bucket : public Zombie
{
public:
int health = 50;
int acc = 100;
void takeDamage(int d)
{
if (acc > 0)
{
acc -= d;
cout << "The Bucket Zombie has taken 25 to the accesory!\n";
}
else{
health -= d;
cout << "The Bucket Zombie has taken 25 damage to health!\n";
}
}
};
class Door : public Zombie
{
public:
int health = 50;
int acc = 25;
void takeDamage(int d)
{
if (acc > 0)
{
acc -= d;
cout << "The Door Zombie has taken 25 to the accesory!";
}
else{
health -= d;
cout << "The Door Zombie has taken 25 damage to health!";
}
}
};
Zombie *Zombie::make_zombie(int choice)
{
if (choice == 1)
{
return new Reg_Zombie();
}
else if (choice == 2)
{
return new Cone();
}
else if (choice == 3)
{
return new Bucket();
}
else if (choice == 4)
{
return new Door();
}
else return NULL;
}
int main(int argc, const char * argv[]) {
Zombie* zomb[100] = NULL;
int choice;
}