title: Undefined reference to 'vtable for xxx'
body: <pre><code>takeaway.o: In function `takeaway':
  project:145: undefined reference to `vtable for takeaway'
  project:145: undefined reference to `vtable for takeaway'
  takeaway.o: In function `~takeaway':
  project:151: undefined reference to `vtable for takeaway'
  project:151: undefined reference to `vtable for takeaway'
  takeaway.o: In function `gameCore':
  project.h:109: undefined reference to `gameCore&lt;int&gt;::initialData(int)'
  collect2: ld returned 1 exit status
  make: *** [takeaway] Error 1
  </code></pre>
  
  <p>I keep getting this Error from the linker , i know it has something to do with inline functions getting a vtable temporarily stored. But what that entails i am not quite sure. I would assume it has something to do with how i call gameCore's constructor in the initilization list of takeaway.cpp</p>
  
  <p>I have a templated class (gameCore.h) 
  and a class (takeaway.cpp) that is inheriting from gameCore
  The vtable error is called 3 times
  1)in takeaways constructor
  2) takeaways destructor
  3)in gameCores constructor</p>
  
  <p>I am using G++
  Here is the code:
  (i know it may seem hard to read but i have marked off exatcly where the erros occur) 
  takeaway.h</p>
  
  <pre><code>#ifndef _TAKEAWAY_H_
  #define _TAKEAWAY_H_
  #include&lt;map&gt;
  #include&lt;cctype&gt;
  #include&lt;stack&gt;
  #include&lt;map&gt;
  #include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;cstdlib&gt;
  #include"gameCore.h"
  #include&lt;vector&gt;
  using namespace std;
  class takeaway : public gameCore&lt;int&gt;
  {
   private:
  
   public:
  // template&lt;class Penny&gt;
   void  textualGame();
   bool isNum(string str);
  // template&lt;class Penny&gt;
   stack&lt;int&gt; initialData(int initial);
  // template&lt;class Position&gt;
   int score (int position);
  // template&lt;class Position&gt;
   stack&lt;int&gt; addStack(int currentPos, stack&lt;int&gt; possiblePositions);
  // template&lt;class Penny&gt;
   takeaway (int initial);
  // template&lt;class Position&gt;
   ~takeaway();
  };
  bool isNum(string str);
  int charToint(char *theChar);
  #endif
  </code></pre>
  
  <p>takeaway.cpp</p>
  
  <pre><code>/*
  Description :
      This game communicates with the gameCore class to determine the results
      of a game of takeaway played between two computers or a computer and human.   
  */
  
  #include "takeaway.h"
  
   /*
   Description:Creates a stack represening initial data
   Note:Change to a vector eventually
   return : stack of int
   */
   stack&lt;int&gt; takeaway:: initialData(int initial){
     stack&lt;int&gt; returnStack;
     int theScore = score(initial);
     int final;
     if(initial ==0)
     {
      final = 1;
     }
     else
     {
      final = 0;
     }
     returnStack.push(theScore);
     returnStack.push(final);
     return returnStack;
   }
  
  
   /*
   Description: a textual representation of the game
   Note: This is still terribly wrong
   */
  
   void textualGame(){
    cout &lt;&lt;"this is the best i could do for a graphical representation";
  
   }
   /*
   Description: Deetermines if a number is even
   Note: Helper function for determining win or loss positions
   Returns: 1 if it is and 0 if it is not
   */
   int takeaway::score(int position){
    if(position % 2 == 0)
    {
       return 1;
    }
    return 0;
   }
   /*
     Description: Will return a stack , withouth the given postion in it
     will contain all positions possible after the given position
     along with anyother that wehre in the given stack.This function
     Must also update the map to represent updated positions
     Takes: a position to check and a stack to return
     Returns: A stack of possible positions.
  
   */
   stack&lt;int&gt;  takeaway::addStack(int currentPos, stack&lt;int&gt; possiblePositions ){
    if(currentPos != 0)
    {
      // If even
      if( currentPos % 2 == 0)
      { 
         // Create a data aray with score of the new positon and mark it as not final
      int data[] = {score(currentPos/2),0};
      vector&lt;int&gt; theData(data, data+sizeof(data));
          int pos = currentPos/2;
         // Add it to the map
         //this -&gt; gamesMap[currentPos/2] = dataArray; 
         this -&gt; gamesMap.insert(std::pair&lt;int, vector&lt;int&gt; &gt;(pos, theData));
         // Add it to the possible positions
         possiblePositions.push(pos);
      }
      if(currentPos % 3 == 0)
      {
  
      int data[] = {score(currentPos/3),0};
         vector&lt;int&gt; theData(data,data+sizeof(data));
         int  pos = currentPos/3;
         //this -&gt; gamesMap[currentPos/3] = dataArray; 
         this -&gt; gamesMap.insert(std::pair&lt;int, vector&lt;int&gt; &gt;(pos, theData));
         possiblePositions.push(pos);
      }
      // Work for the position that represents taking one penny
      int minusFinal = 0;
      if(currentPos - 1 == 0)
      {
        minusFinal = 1;
      }
      int data[] = {score(currentPos - 1),minusFinal};
      vector&lt;int&gt; theData(data,data+sizeof(data));
      int pos  = currentPos - 1;
     // this -&gt; gamesMap[currentPos -1] = dataArary
      this-&gt;gamesMap.insert(std::pair&lt;int,vector&lt;int&gt; &gt;(pos, theData));
      possiblePositions.push(pos);
    }
    return possiblePositions;
  
   }
   /*
   Description: Constructor for the takeaway game
  OA takes: a initial position, and initial data for it
  
   */
   takeaway::takeaway(int initial):gameCore&lt;int&gt;::gameCore(initial){ //&lt;--- ERROR HERE
   //Constructor
   }
   /*
   Description: Destuctor
   */
   takeaway::~takeaway(){ // &lt;--------------------- ERROR HERE
   //Destructor
   }
  
  
  //checks input and creates game.
  int main(int argc, char* argv[]){
    int numberPennies ;
    string game = argv[0];
    if(argc == 2 &amp;&amp; isNum(argv[1]) )
    {
      int pennies = charToint(argv[1]);
       takeaway gameInstance(pennies ); // Creates a instance of $
    }
   //  else if(argc == 3 &amp;&amp; argv[1] == "play" &amp;&amp; isNum(argv[2]) )
   // {
   //   int pennies = charToint(argv[2]);
   //   takeaway&lt;int&gt; gameInstance(pennies); // Craete a human playab$
   // }
    else
    {
      cerr &lt;&lt; "Error-&gt;Usage: " &lt;&lt; game &lt;&lt;" [play] numberOfPennies \n";
      exit (1);
    }
   return 0;
   }
  
  //Converts a char to a integer
  int charToint(char *theChar){
    int theInt = atoi(theChar);
    return theInt;
  }
   //Determines if a string is numeric
  bool isNum(string str){ 
    for(int i = 0;i &lt; str.length() ;i++){
     if(isdigit(str[i]) != 1)
     {
       cerr &lt;&lt; "Error-&gt;Input: Number must be a Positive Integer the charecter '" &lt;&lt; str[i]&lt;&lt; "' invalidated your input. \n" ;
       exit(1);
       return false;
     }
    }
    return true;
  }
  </code></pre>
  
  <p>gameCore.h</p>
  
  <pre><code>/*
  gameCore.h
  
  Description:
      This class created gameMap that are written as a template
      They will communicate with the specific game and the algorithm
      To keep track of positions ans there values.
  */
  #ifndef GAMECORE_H
  #define GAMECORE_H
  #include &lt;map&gt;
  #include &lt;stack&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  
  template &lt;class Position&gt;
  class gameCore
  {
   protected:
      //Best Move used by algorithim
      Position bestMove;
      //The current highest score used by the algorithim
      int highestScore ;
      //Stack to be used to remmeber what move created the score
      stack&lt;Position&gt; movedFrom;
      //Stack used for the algorithim.
      stack&lt;Position&gt; curWorkingPos;
      //The actual Map that the data will be held in.
      map&lt;Position,vector&lt;int&gt; &gt; gamesMap;
   public:
  
      /*
      Description : finds the data array for a poisition
      takes: a Position
      Returns: a array of integers /**
      */
      virtual stack&lt;int&gt; initialData(Position pos) = 0;
          /*
      Description: Game must implement a way to determine a positions
      score.
  
      */
          virtual int score(Position pos) = 0;
          /*
      Description: A Graphical representation of the game
  
      */
      virtual void textualGame() = 0;
  
      /*
      Description: a virtual function implemented by the child class
      it will return a stack without the given position in it.This stack
      will contain all positions available from the given postion as well as 
      all position already in the given stack. Also it will update the map with
      all generated positions.
      TAkes: a postion to check and a stack of currently working positons.
  
      */
      virtual stack&lt;Position&gt; addStack(Position currentPos, stack&lt;Position&gt; possiblePositions ) = 0;
      /*
         Description:Constructor that
         Creates a Map with positions as the key.
         And an array of two integers that represent the positions
         value and if we have moved here in the past.
         Takes: a Initial Position and a Array of integers
      */
      gameCore(Position initial){              // &lt;-----ERROR HERE
         //Determine the initial data and add it to the map and queue.
         stack&lt;int&gt; theData = initialData(initial);
         int first = theData.top();
             theData.pop();
             int second = theData.top();
         theData.pop();
         int initialData[] = {first,second};
             vector&lt;int&gt; posData(initialData,initialData+sizeof(initialData));
         gamesMap[initial] = posData;
         curWorkingPos.push(initial);
      }
      /*
      Description:
         A destructor for the class
      */
       ~gameCore(){
          //I do nothing but , this class needs a destructor
  
      }
      /*
         Description: Takes the current position and returns 
         that positions Score.
         Takes: A position 
         Returns:A integer that is a positions score.
  
      */
      int getPosScore(Position thePos) const {
          return this -&gt;gamesMap.find(thePos)-&gt;second[0];
      }
      /*
      Description: Adds values to a stack based on the current position
      Takes: a poistion
      */
      void updateStack(Position curPos){
          this -&gt;curWorkingPos =addStack(curPos,this -&gt;curWorkingPos ); // get a stack from the game
          // The game has a function that takes a position and a stack and based on the positions returns a stack identical to the last but with added values that represent valid moves from the postion./
      }
      /*
         Description : Takes a positions and returns a integer
         that depends on if the position is a final pos or not
         Takes: A position
         Returns: A Bool that represents if the position is a final(1)  or not (0).
  
      */
          // Possible change
      bool isFinal(Position thePos) {     
          typename map&lt;Position,vector&lt;int&gt; &gt;::iterator iter =  this -&gt;gamesMap.find(thePos);
          return iter-&gt;second[1] == 1 ;
      }
      /*
      Description: Based on the given position determine if a move needs to be made.
      (if not this is a end game position and it will return itself) If a move needs
      to be made it will return the position to move to that is ideal.
      Note: (because all positions can be represented as integers for any game , the return
      type is a integer)
  
      */
      int evaluatePosition(Position possiblePosition ){
             if(isFinal(possiblePosition)) //If this is a final position
          {
             return  getPosScore(possiblePosition);  //Return the score 
          }
             else
             {
           updateStack(possiblePosition); //Put all possible positions from this in thte stack
           while(this -&gt; curWorkingPos.size() != 0)
           {
             this -&gt; movedFrom.push(this-&gt;curWorkingPos.front()); //take the top of the possible positions stack and set it the the moved from stack
             this -&gt; curWorkingPos.pop();
             int curScore =  evaluatePosition(this -&gt;movedFrom.top());  //Recursive call for school
             curScore = curScore * -1; //Negate the score
             if(curScore &gt; this -&gt; highestScore) // if the score resulting from this position is biggest seen
             {
               highestScore = curScore;
               this -&gt;movedFrom.pop();  //do this first to get rid of the the lowest point
               this -&gt; bestMove = this -&gt;movedFrom.top();  // mark where the lowest point came from
             }
            else
             {
               this -&gt; movedFrom.pop(); 
             }
           }
             }
          return this -&gt; bestMove;
      }
      //A Structure to determine if a position has a lower value than the second
      struct posCompare{
          bool operator() (Position pos1,Position pos2) const {
              return (pos1.getPosScore() &lt; pos2.getPosScore());
              }
          };
  };
  #endif
  </code></pre>