0

Keeping getting into errors in my code...this looks to be the wierdest so far...

class bug: public living{
      protected:
              bool ate;
              int energy;
      public:
             virtual void moveToFood(point hunter, point food);
             bool eatIt(point hunter, point food){
                  int hx, hy, fx, fy;
                  hx=hunter.getx();
                  hy=hunter.gety();
                  fx=food.getx();
                  fy=food.gety();
                  if((hy==fy)&&(hx==fx))
                       ate=true;
                  else
                       ate=false;
                  return ate;
             }
             void setEnergy(int nrg){energy=nrg;}
             int getEnergy(){return energy;}
             virtual void print()const{location.print();}
};
class ladybug: public bug{
      public:
             ladybug(int u, int v){location.set(u,v);energy=0;}
             void moveToFood(point hunter, point food){
                  int hx, hy, fx, fy;
                  hx=hunter.getx();
                  hy=hunter.gety();
                  fx=food.getx();
                  fy=food.gety();
                  if(hx<fx)
                  {
                       hx+=2;
                       if(hx>fx)
                       hx--;
                  }         
                  else if(hx>fx)
                  {
                       hx-=2;
                       if(hx<fx)
                       hx++;
                  }
                  else if(hy<fy)
                  {
                       hy+=2;
                       if(hy>fy)
                       hy--;
                  }
                  else if(hy>fy)
                  {
                       hy-=2;
                       if(hy<fy)
                       hy++;      
                  }
                  location.set(hx,hy);
             }
            void print()const{
                  cout<<"The ladybug is at ";
                  location.print();
                  if(ate==true)
                  cout<<"It just ate an aphid."<<endl;
                  else
                  cout<<"It is still hungry."<<endl;
             }
};

When ever I try to declare a ladybug or other derived class object I get that
undefined reference to 'vtable for bug' error. What is going on?

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by daviddoria
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.