title: Passing iterator value rather than reference to function
body: <p>I'm trying to pass my struct in an iterator into a function that accesses the struct using the "."-operator. I'm trying to wrap my head around the difference of passing values, pointers and addresses and I just can't figure this one out.</p>
  
  <p>Below is the error from the compiler and the code that generates the error.</p>
  
  <p>Compiler error:</p>
  
  <blockquote>
    <p>server-iterative.cpp:222:109: error: invalid initialization of
    reference of type ‘const ConnectionData&amp;’ from expression of type
    ‘ConnectionData*’
        server-iterative.cpp:134:13: error: in passing argument 1 of ‘bool is_invalid_connection(const ConnectionData&amp;)’</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>struct ConnectionData
  {
      EConnState state;
      int sock;
      size_t bufferOffset, bufferSize; 
      char buffer[kTransferBufferSize+1];
  };
  
  for(std::vector&lt;ConnectionData&gt;::iterator it = connections.begin(); it != connections.end(); ++it){
      if(FD_ISSET(it-&gt;sock, &amp;rset)){
          if(process_client_recv(*it) == false){
              close(it-&gt;sock);
              bool test = is_invalid_connection(&amp;(*it));
          }
      }
  }
  
  static bool is_invalid_connection( const ConnectionData&amp; cd )
  {
      return cd.sock == -1;
  }
  </code></pre>