title: Asio::async_connect and io_service.run don't compile
body: <p>I am learning to use Boost ASIO. Here is my code adapted from the Boost doc's <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/example/chat/chat_client.cpp" rel="nofollow">chat example</a>.</p>
  
  <pre><code>class AsioCommunicationService {
  AsioCommunicationService::AsioCommunicationService(
          boost::asio::io_service&amp; io_service,
          tcp::resolver::iterator endpoint_iterator)
      : io_service_(io_service),
        socket_(io_service)
  {
      boost::asio::async_connect(socket_, endpoint_iterator,
          boost::bind(&amp;AsioCommunicationService::handle_connect, this,
          boost::asio::placeholders::error));
  }
  
  
  
  void AsioCommunicationService::handle_connect(const boost::system::error_code&amp; error)
  {
      if (!error)
      {
        boost::asio::async_read(socket_,
            boost::asio::buffer(read_msg_.data(), LampMessage::header_length),
            boost::bind(&amp;AsioCommunicationService::handle_read_header, this,
            boost::asio::placeholders::error));
      }
  }
  }
  
  
  class Connection
  {
      m_session = std::shared_ptr&lt;AsioCommunicationService&gt;(
              new AsioCommunicationService(io_service, iterator));
      boost::thread t(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service));
  }
  </code></pre>
  
  <p>When compiling, I got an error that says ‘async_connect’ is not a member of ‘boost::asio’. Clearly, async_connect is not a member of boost asio, but of socket, as far as what the IDE tells me. I'm using libasiodev 1.41.3. </p>
  
  <p>I tried to modify the call to this </p>
  
  <pre><code>tcp::endpoint endpoint = *endpoint_iterator;
  socket_.async_connect(endpoint,
      boost::bind(&amp;AsioCommunicationService::handle_connect, this,
      boost::asio::placeholders::error, ++endpoint_iterator));
  //Got this error: instantiated from ‘boost::_bi::bind_t&lt;boost::_bi::unspecified, void (networkService::AsioCommunicationService::*)(const boost::system::error_code&amp;), boost::_bi::list3&lt;boost::_bi::value&lt;networkService::AsioCommunicationService*&gt;, boost::arg&lt;1&gt; (*)(), boost::_bi::value&lt;boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt; &gt; &gt; &gt;’
  </code></pre>
  
  <p>UPDATE:
      After changing the handle_connect signature to include the iterator parameter, I succesfully compiled that line. However, the compiler is now stuck at the include to thread.hpp </p>
  
  <pre><code>#include &lt;boost/thread.hpp&gt;
  //ERROR: In function ‘boost::thread&amp;&amp; boost::move(boost::thread&amp;&amp;)’:
  ///usr/include/boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type ‘boost::thread&amp;&amp;’ from expression of type ‘boost::thread’
  //In file included from /usr/include/boost/thread/detail/thread_heap_alloc.hpp:17:0,
  //             from /usr/include/boost/thread/detail/thread.hpp:13,
  //             from /usr/include/boost/thread/thread.hpp:22,
  //             from /usr/include/boost/thread.hpp:13,
  //             from /home/son/dev/logistics/src/frameworks/networkService/NetworkConnection.cpp:13:
  ///usr/include/boost/thread/pthread/thread_heap_alloc.hpp: In function ‘T* boost::detail::heap_new(A1&amp;&amp;) [with T = boost::detail::thread_data&lt;void (*)()&gt;, A1 = void (*&amp;)()]’:
  ///usr/include/boost/thread/detail/thread.hpp:130:95:   instantiated from here
  ///usr/include/boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind ‘void (*)()’ lvalue to ‘void (*&amp;&amp;)()’
  ///usr/include/boost/thread/detail/thread.hpp:43:13: error:   initializing argument 1 of ‘boost::detail::thread_data&lt;F&gt;::thread_data(F&amp;&amp;) [with F = void (*)()]’
  </code></pre>
  
  <p>For some reason, I can't start a new thread with the call boost::thread t(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service)); , even though it works if I replace it by a simple call to io_service.run();</p>