title: Evaluating vector::empty() is crashing the program
body: <p>I'm currently writing an extension of another program (Specificly, of a game) and i've been stuck on solving the following problem for hours now.</p>
  
  <p>Any time a player (client) connects to the game server, the <code>OnClientConnected(int client_number);</code> function is called. In this function, i create an instance of a <code>CPlayer</code> class that stores player information, such as health, speed and any other data i might require. This instance, is then stored by the following class:</p>
  
  <pre><code>class CPlayerManager
  {
      std::vector&lt;Player*&gt; *player_list;
  
      public:
      CPlayerManager();
      ~CPlayerManager();
      void AddPlayer(client_id)
      *CPlayer GetPlayerInstance(client_id);
  }
  
  CPlayerManager()
  {
       player_list = new std::vector&lt;Player*&gt;;
  }
  
  ~CPlayerManager()
  {
       delete player_list;
  }
  
  void CPlayerManager::AddPlayer(client_id)
  {
       CPlayer *player = new CPlayer(client_id);
       player_list-&gt;push_back(player);
  }
  
  void *CPlayerManager::GetPlayerInstance(client_id)
  {
       if(player_list-&gt;empty())
       {
           return NULL;
       }
  
       for(std::vector&lt;CPlayer*&gt;::size_type i = 0; i != player_list-&gt;size(); i++)
   {
      int client = player_list-&gt;at(i)-&gt;GetClientId();
      if(client_id == client)
      {
          return player_list-&gt;at(i);
      }
   }
   return NULL;
  }
  </code></pre>
  
  <p>Original game functions use a client indexes as arguments and return values, so i need to obtain player instances from client indexes all the time. The problem is in the <code>GetPlayerInstance</code> function. This function might be called when NO client has been yet initialized and stored by the <code>CPlayerManager</code> instance, so we might have an empty vector.
  Anytime the <code>GetPlayerInstance</code> function is called when the vector is empty, the entire game server crashes. I've been debugging a bit, and i noticed that the program crashes right in:</p>
  
  <pre><code>//Code reaches here
  if(player_list-&gt;empty())
  {
      //code does not reach here
      return NULL;
  }
  </code></pre>
  
  <p>Doing <code>bool empty = player_list-&gt;empty())</code> works until i evaluate <code>empty</code> on the <code>if</code> statement.</p>
  
  <p>What could be causing this strange crash?</p>