Linker Error: undefined reference to `vtable`

Hi! I am trying to compile and start testing an agent based simulation of a zombie apocalypse, however I use inheritance and I keep getting a linker error that says, exactly: "[Linker error] undefined reference to `vtable for Human'" Any guidance or help would be very much appreciated, as most of the `vtable problems I find on the net seem either not to be the same situation or aren't answered. I will keep looking however. Thanks in advance!

Here are my files:

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdlib>
#include <iostream>
#include "definitions.h"

using namespace std;

int main(int argc, char *argv[])
{
    
    int w=500;
    int h=500;
    
    int squares=w*h;
    Random X(1,squares,squares);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


definitions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef definitions_h
#define definitions_h
class Creature;
class Item;
class Coords;

class Grid
{
      
public:
      Creature*** cboard;
      Item*** iboard;
      
      int WIDTH;
      int HEIGHT;
      
      Grid(int WIDTHVALUE, int HEIGHTVALUE);
      void FillGrid(); //initializes grid object with humans and zombies  
      void Refresh(); //calls Creature::Die(),Move(),Attack(),Breed() on every square
      void UpdateBuffer(char** buffer);
      bool isEmpty(int startx, int starty, int dir);
      char CreatureType(int xcoord, int ycoord);
      char CreatureType(int startx, int starty, int dir);
      
};

class Random
{
    public:
        int* rptr;
        void Print();
        Random(int MIN, int MAX, int LEN);
        ~Random();
    private:
        bool alreadyused(int checkthis, int len, int* rptr);
        bool isClean();
        int len;
};

class Coords
{
  public:   
      int x;
      int y;
      int MaxX;
      int MaxY;
      
      Coords() {x=0; y=0; MaxX=0; MaxY=0;}
      Coords(int X, int Y, int WIDTH, int HEIGHT) {x=X; y=Y; MaxX=WIDTH; MaxY=HEIGHT; }
      
      void MoveRight();
      void MoveLeft();
      void MoveUp();
      void MoveDown();
      void MoveUpRight();
      void MoveUpLeft();
      void MoveDownRight();
      void MoveDownLeft();
      void MoveDir(int dir);
      void setx(int X) {x=X;}
      void sety(int Y) {y=Y;}
};

class Creature
{
      
public:
      bool alive;
      Coords Location;
      char displayletter;
      
      Creature() {Location.x=0; Location.y=0;}
      Creature(int i, int j) {Location.setx(i); Location.sety(j);} 
      
      virtual void Attack(Grid G) =0;
      virtual void AttackCreature(Grid G, int attackdirection) =0;
      virtual void Breed(Grid G) =0;
      
      virtual ~Creature() {}
      
      void Die();
      void Move(Grid G);
      int DecideSquare(Grid G);
      void MoveTo(Grid G, int dir); 
      
};

class Human : public Creature  
{
public:      
      bool armed; //if armed, chances of winning fight increased for next fight 
      bool vaccinated; //if vaccinated, no chance of getting infected
      
      int bitecount; //if a human is bitten, bite count is set to a random number
      int breedcount; //if a human goes x steps without combat, will breed if next to a human
      int starvecount; //if a human does not eat in x steps, will die 
      
      Human() : Creature::Creature() { displayletter='H'; armed=0; vaccinated=0; bitecount=0; breedcount=8; starvecount=10;} 
      Human(int i, int j) : Creature::Creature(i,j) { displayletter='H'; armed=0; vaccinated=0; bitecount=0; breedcount=8; starvecount=10;}
      
      
      void Attack(Grid G);
      void AttackCreature(Grid G, int attackdirection);
      void Breed(Grid G); //will breed after x steps and next to human
      
      int DecideAttack(Grid G);
      
};

class Zombie : public Creature
{
   public:
      Zombie() : Creature::Creature() {displayletter='Z';}
      Zombie(int i, int j) : Creature::Creature(i,j) {displayletter='Z';}
      
      
      void Attack(Grid G); 
      void AttackCreature(Grid G, int attackdirection);
      void Breed(Grid G) {} //does nothing
      
      
      int DecideAttack(Grid G);
      
   
};

class Item
{
      
};

#endif 


I can include the implementations if requested, but at this point I think the problem is with how I'm declaring and with the inheritance.
Have you written the source cod for your classes methods? I can't see them here.
The problem was I did not have an implementation of Human::Attack(Grid G) like I promised I would with virtual Creature::Attack(Grid G) !!
Topic archived. No new replies allowed.