954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Umm...undefined reference to vtable

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?

aleX_X
Newbie Poster
9 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Here are a handful of explanations and possible solutions:
http://www.daniweb.com/forums/thread114299.html

daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: