0

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;

}
TCripe4
  • 19
  • 4
  • The shown code in this question fails to meet stackoverflow.com's requirements for a [mre], and because of that it is unlikely that anyone on stackoverflow.com can determine the problem. This question must be [edit]ed to show a minimal example, no more than one or two pages of code (the "minimal" part), that anyone can cut/paste, compile, run, and reproduce the described problem (the "reproducible" part) ***exactly as shown*** (this includes any ancillary information, like the input to the program). See [ask] for more information. – Sam Varshavchik Mar 03 '20 at 02:56
  • Can not reproduce. Can you show the line where the error occurs? – con ko Mar 03 '20 at 02:59
  • This question is closed. So I failed to add an answer. It seems you've wrongly created a instance of `Zoombie`. But not in the code you pasted. – con ko Mar 03 '20 at 03:02
  • So I just deleted the Zombie* zombie[100] = NULL code and the error went away. How would I create a vector or array of zombies? – TCripe4 Mar 03 '20 at 03:23
  • You are missing braces: `Zombie* zomb[100] = {NULL};` – 001 Mar 03 '20 at 03:53

0 Answers0