title: c++ pass a map by reference into function
body: <p>How can I pass a <code>map</code> by <code>reference</code> into a function? Visual Studio 2010 is giving me an <code>unresolved externals</code> error. Currently, I have the following simplified code: </p>
  
  <pre><code>void function1(){
      map&lt;int, int&gt; * my_map = new map&lt;int, int&gt;(); 
      function2(*my_map); 
  }
  
  void function2(map&lt;int, int&gt; &amp;temp_map){
      //do stuff with the map
  }
  </code></pre>
  
  <p>There's a few answers to similar questions here, but they make use of <code>typedef</code> and adding <code>std::</code> to the beginning of the definition but I'm really not sure why.</p>
  
  <pre><code>int ComputerPlayer::getBestMoves(){
      //will return the pit number of the best possible move. 
  
      //map to hold pit numbers and rankings for each possible pit number.
      //map&lt;pitNumber, rank&gt; only adds pit numbers to map if they have seeds in them.
  
      std::map&lt;int, int&gt; possiblePits; //map
      std::map&lt;int, int&gt;::iterator it; //iterator for map
      for(int index = 1; index &lt;= getBoardSize(); index++){
          if(_board.getPitValue(index) &gt; 0){
              possiblePits.insert( pair&lt;int, int&gt;(index, 0) ); 
          }
      }
  
      int tempBoardSize = _board.getBoardSize();
  
      //loop that will analyze all possible pits in the map
      for(it = possiblePits.begin(); it != possiblePits.end(); it++){
          Board tempBoard = _board;
          int pitNum = it-&gt;first; 
  
          int score = analyzePlay(pitNum, tempBoard, possiblePits);
      }
      return 0; 
  }
  
  int analyzePlay(int pitNum, Board tempBoard, std::map&lt;int, int&gt; &amp;possibleMoves){
      int tempBoardSize = tempBoard.getBoardSize(); 
      int tempSeeds = tempBoard.getPitValue(pitNum);
      int lastPitSown; 
  
      tempBoard.setPitToZero(pitNum); 
  
      for(int index = 1; index &lt;= tempSeeds; index++){
  
          if(pitNum == tempBoardSize * 2 + 1){
              //skips over human's score pit 
              pitNum += 2; 
              lastPitSown = pitNum;
              tempBoard.incrementPit(pitNum);
          }
          else{
              pitNum++;
              lastPitSown = pitNum;
              tempBoard.incrementPit(pitNum);
          }
      }
  
      if(tempBoard.getPitValue(lastPitSown) == 1 &amp;&amp; lastPitSown &gt;= tempBoardSize + 2 &amp;&amp; lastPitSown &lt;= tempBoardSize * 2 + 1){
          //turn ends. last seed sown into empty pit on opponent side. 
  
      }
      else if(tempBoard.getPitValue(lastPitSown) &gt; 1 &amp;&amp; lastPitSown != tempBoardSize + 1){
          //keep playing with next pit. last seed was sown into non-empty pit. 
  
      }
      else if(lastPitSown == tempBoardSize + 1){
          //extra turn. last seed sown into score pit.
  
      }
      else if(tempBoard.getPitValue(lastPitSown) == 1 &amp;&amp; lastPitSown != tempBoardSize + 1 &amp;&amp; lastPitSown &lt;= tempBoardSize &amp;&amp; lastPitSown &gt;= 1 ){
          //turn ends. last seed sown into empty pit on your side. capture.
  
  
      }
      return 0;
  }
  </code></pre>
  
  <p>The error I was getting: </p>
  
  <pre><code>Error   1   error LNK2019: unresolved external symbol "public: int __thiscall ComputerPlayer::analyzePlay(int,class Board,class std::map&lt;int,int,struct std::less&lt;int&gt;,class std::allocator&lt;struct std::pair&lt;int const ,int&gt; &gt; &gt; &amp;)" (?analyzePlay@ComputerPlayer@@QAEHHVBoard@@AAV?$map@HHU?$less@H@std@@V?$allocator@U?$pair@$$CBHH@std@@@2@@std@@@Z) referenced in function "public: int __thiscallComputerPlayer::getBestMoves(void)" (?getBestMoves@ComputerPlayer@@QAEHXZ)    C:\Users\Josh\Dropbox\Congkak_2\Congkak_2\ComputerPlayer.obj
  Error   2   error LNK1120: 1 unresolved externals   C:\Users\Josh\Dropbox\Congkak_2\Debug\Congkak_2.exe
  </code></pre>