title: c++ undefined reference to `vtable
body: <p>My question has changed from the other one I have posted. I started out with multiple files and decided to put it all in one main.cpp file for now just to get it working.</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class arrayListType {
      public:
          bool isEmpty() ;
          bool isFull() ;
          int listSize() ;
          int maxListSize() ;
          void print() ;
          bool isItemAtEqual(int location, int item) ;
          virtual void insertAt(int location, int insertItem) = 0;
          virtual void insertEnd(int insertItem) = 0;
          void removeAt(int location);
          void retrieveAt(int location, int&amp; retItem) ;
          virtual void replaceAt(int location, int repItem) = 0;
          void clearList();
          virtual int seqSearch(int searchItem) const  = 0;
          virtual void remove(int removeItem) = 0;
          arrayListType (int size = 100);
          arrayListType ( arrayListType&amp; otherList);
          virtual ~arrayListType();
      protected:
          int *list;
          int length;
          int maxSize;
  };
  
  
  bool arrayListType::isEmpty()  {
      return (length == 0);
  }
  bool arrayListType::isFull()  {
      return (length == maxSize);
  }
  int arrayListType::listSize()  {
      return length;
  }
  int arrayListType::maxListSize()  {
      return maxSize;
  }
  void arrayListType::print()  {
      for (int i = 0; i &lt; length; i++)
          cout &lt;&lt; list[i] &lt;&lt; " ";
      cout &lt;&lt; endl;
  }
  bool arrayListType::isItemAtEqual(int location, int item)  {
      if (location &lt; 0 || location &gt;= length) {
          cout &lt;&lt; "The location of the item to be compared is out range." &lt;&lt; endl;
          return false;
      }
      else
          return(list[location] == item);
  }
  
  
  void arrayListType::removeAt(int location) {
      if (location &lt; 0 || location &gt;= length){
          cout &lt;&lt; "The location of the item to be removed is out of range." &lt;&lt; endl;
      }
      else {
          for (int i = location; i &lt; length -1; i++)
              list[i] = list[i+1];
          length--;
      }
  }
  void arrayListType::retrieveAt(int location, int&amp; retItem)  {
      if (location &lt; 0 || location &gt;= length) {
          cout &lt;&lt; "The location of the item to be retrieved is out of range." &lt;&lt; endl;
      }
      else
          retItem = list[location];
  }
  
  
  void arrayListType::clearList() {
      length = 0;
  }
  
  
  arrayListType::arrayListType (int size) {
      if (size &lt;= 0) {
          cout &lt;&lt; "The array size must be positive. Creating an array of the size 100." &lt;&lt; endl;
          maxSize = 100;
      }
      else
          maxSize = size;
      length = 0;
      list = new int[maxSize];
  }
  
  class orderedArrayListType: public arrayListType {
  
      public:
          void insertAt(int location, int insertItem);
          void insertEnd(int insertItem);
          void replaceAt(int location, int repItem);
          int seqSearch(int searchItem) const;
          void insert (int insertItem);
          void remove (int removeItem);
          orderedArrayListType (int size = 100);
          ~orderedArrayListType();
      private:
          void quickSort();
  };
  
  
  
  void orderedArrayListType::quickSort(){
  //private function for sorting "list."
  //using a "quicksort" method
  //addapted from: http://www.algolist.net/Algorithms/Sorting/Quicksort
      if (length == 0) {
          cout &lt;&lt; "Cannot sort an ampty list." &lt;&lt; endl;
      }
      else {
          int left = 0, right = length;
          int i = left, j = right;
      int tmp;
      int pivot = list[(left + right) / 2];
      /* partition */
      while (i &lt;= j) {
          while (list[i] &lt; pivot)
              i++;
          while (list[j] &gt; pivot)
              j--;
          if (i &lt;= j) {
              tmp = list[i];
              list[i] = list[j];
              list[j] = tmp;
              i++;
              j--;
          }
      };
      /* recursion */
      if (left &lt; j)
          quickSort();
      if (i &lt; right)
          quickSort();
      }
  }
  
  
  
  
  void orderedArrayListType::insertAt(int location, int insertItem){
  
      if (location &lt; 0 || location &gt;= length){
          cout &lt;&lt; "The location of the item to be removed "
          &lt;&lt; "is out of range." &lt;&lt; endl;
      }
      else if(length == maxSize){
          cout &lt;&lt; "Cannot insert in a full list." &lt;&lt; endl;
      }
      else {
          for (int j = length; j &lt; location; j--){ 
              list[j+1] = list[j]; 
              /* 
              Start at the end of the array and move each item 
              out by one. Coninue until list[j] is at the 
              location, then set the list[location] to the value.
              */  
          }
          list[location] = insertItem;
          length++;
      }
      quickSort();
  }
  
  void orderedArrayListType::insertEnd(int insertItem) {
  
      if (length == maxSize){
          cout &lt;&lt; "Cannot insert in a full list." &lt;&lt; endl;
      }
      else {
          list[length] = insertItem;
          length++;
      }
      quickSort();
  }
  
  
  void orderedArrayListType::replaceAt(int location, int repItem) {
      if (location &lt; 0 || location &gt;= length){
          cout &lt;&lt; "The location of the item to be replaced "
          &lt;&lt; "is out of range." &lt;&lt; endl;
      }
      else
          list[location] = repItem;
      quickSort();
  }
  
  int orderedArrayListType::seqSearch(int searchItem) const {
  
      int loc;
      bool found = false;
      loc = 0;
      while (loc &lt; length &amp;&amp; !found) {
          if (list[loc] == searchItem)
              found = true;
          else
              loc++;
      }
      if (found)
          return loc;
      else
          return -1;
  }
  
  
  void orderedArrayListType::insert (int insertItem){
      if (length == 0){
          list[length++] = insertItem;
      }
      else if (length == maxSize){
          cout &lt;&lt; "Cannot insert in a full list." &lt;&lt; endl;
      }
      else {
          int loc;
          bool found = false;
          for (loc= 0; loc &lt; length; loc++){
              if (list[loc] &gt;= insertItem){
                  found = true;
                  break;
              }
          }
          for (int i = length; i &gt; loc; i--) {
              list[i] = list[i-1];
          }
          list[loc] = insertItem;
          length++;
      }
      quickSort();
  }
  void orderedArrayListType::remove (int removeItem) {
  
      int loc;
  
      if (length == 0)
          cout &lt;&lt; "Cannot Delete from an ampty list." &lt;&lt; endl;
      else {
          loc = seqSearch(removeItem);
          if (loc != -1)
              removeAt(loc);
          else
              cout &lt;&lt; "The item to be deleted is not in the list." &lt;&lt; endl;
      }
  }
  
  
  orderedArrayListType::orderedArrayListType (int size)
      :arrayListType(size){
  }
  
  
  
  
  
  int main() {
  
  //  orderedArrayList intlist(25);
  //  orderedArrayListType intList = new orderedArrayListType(25);
  }
  </code></pre>
  
  <p>The exact error message:</p>
  
  <blockquote>
    <p>/tmp/ccdTFaE0.o: In function <code>arrayListType::arrayListType(int)':
    main3.cpp:(.text+0x25c): undefined reference to</code>vtable for
    arrayListType'
    /tmp/ccdTFaE0.o:(.rodata._ZTV20orderedArrayListType[vtable for
    orderedArrayListType]+0<br>
    x38): undefined reference to
    <code>orderedArrayListType::~orderedArrayListType()'
    /tmp/ccdTFaE0.o:(.rodata._ZTV20orderedArrayListType[vtable for
    orderedArrayListType]+0<br>
    x40): undefined reference to
    </code>orderedArrayListType::~orderedArrayListType()'
    /tmp/ccdTFaE0.o:(.rodata._ZTI20orderedArrayListType[typeinfo for
    orderedArrayListType]<br>
    +0x10): undefined reference to `typeinfo for arrayListType' collect2: ld returned 1 exit status</p>
  </blockquote>
  
  <p>tldr;</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class arrayListType {
      public:
          bool isEmpty() const;
                  ...
                  arrayListType (int size = 100);
          arrayListType ( arrayListType&amp; otherList);
          virtual ~arrayListType();
      protected:
          int *list;
          int length;
          int maxSize;
  };
  
  
  //definitions 
  bool arrayListType::isEmpty()  {
      return (length == 0);
  }
  
  class orderedArrayListType: public arrayListType {
  
      public:
          void insertAt(int location, int insertItem);
          ...
          orderedArrayListType (int size = 100);
          ~orderedArrayListType();
      private:
          void quickSort();
  };
  
  
  
  void orderedArrayListType::quickSort(){
   ...
   }
  
  
  
  
  void orderedArrayListType::insertAt(int location, int insertItem){
  
         ....     
  
      quickSort();
  }
  
     orderedArrayListType::orderedArrayListType (int size)
      :arrayListType(size){
  }
  
  
  int main() {
  
      orderedArrayList intlist(25);
  //  orderedArrayListType intList = new orderedArrayListType(25);
  }
  </code></pre>