title: std::thread pass by reference calls copy constructor
body: <p>Well I have an issue with passing data into a thread using std::thread. I thought I understood the general semantics of copy constructors, etc. but it seems I don't quite grasp the problem.  I have a simple class called Log that has hidden it's copy constructor thusly:</p>
  
  <pre><code>class Log
  {
  public:
      Log(const char filename[], const bool outputToConsole = false);
      virtual ~Log(void);
  
      //modify behavior
      void appendStream(std::ostream *);
      //commit a new message
      void commitStatus(const std::string str);
  
  private:
      //members
      std::ofstream fileStream;
      std::list&lt;std::ostream *&gt; listOfStreams;
  
      //disable copy constructor and assignment operator
      Log(const Log &amp;);
      Log &amp; operator=(const Log &amp;);
  }
  </code></pre>
  
  <p>now I have a main based heavily on <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp11/echo/blocking_tcp_echo_server.cpp">http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/example/cpp11/echo/blocking_tcp_echo_server.cpp</a></p>
  
  <pre><code>int main()
  {
      static int portNumber = 10000;
  
      Log logger("ServerLog.txt", true);
      logger.commitStatus("Log Test String");
  
      try {
          boost::asio::io_service ioService;
          server(ioService, portNumber, logger);
      }
      catch (std::exception &amp;e)
      {
          std::cerr &lt;&lt; "Exception " &lt;&lt; e.what() &lt;&lt; std::endl;
          logger.commitStatus(e.what());
      }
  
      return 0;
  }
  </code></pre>
  
  <p>You can see that main calls the function server and passes the IOService, portNumber and logger. The logger is passed by reference, thusly:</p>
  
  <pre><code>using boost::asio::ip::tcp;
  
  void server(boost::asio::io_service &amp;ioService, unsigned int port, Log &amp;logger)
  {
      logger.commitStatus("Server Start");
  
      tcp::acceptor acc(ioService, tcp::endpoint(tcp::v4(), port));
  
      while(true)
      {
          tcp::socket sock(ioService);
          acc.accept(sock);
  
          std::thread newThread(session, &amp;sock, logger);
          newThread.detach();
      }
  
      logger.commitStatus("Server closed");
  }
  </code></pre>
  
  <p>I get a compiler error when I try to pass the logger (or the socket) to the thread by reference, but I do not get the error when passing it to the session() by reference</p>
  
  <pre><code>static void session(tcp::socket *sock, Log &amp;logger)
  {
      std::cout &lt;&lt; " session () " &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Now I thought that I understood correctly that a reference is the same as passing a pointer. That is, it does not call the copy constructor, it simply passes the pointer, which it lets you syntactically treat like it's not a pointer.</p>
  
  <blockquote>
    <p>error C2248: 'Log::Log' : cannot access private member declared in class 'Log'</p>
    
    <p>1>          \log.h(55) : see declaration of 'Log::Log'</p>
    
    <p>1>          \log.h(28) : see declaration of 'Log'</p>
    
    <p>...</p>
    
    <p>: see reference to function template instantiation 'std::thread::thread(_Fn,_V0_t &amp;&amp;,_V1_t)' being compiled</p>
    
    <p>1>          with</p>
    
    <p>1>          [</p>
    
    <p>1>              <em>Fn=void (</em>_cdecl *)(boost::asio::ip::tcp::socket *,Log &amp;),</p>
    
    <p>1>              _V0_t=boost::asio::ip::tcp::socket *,</p>
    
    <p>1>              _V1_t=Log &amp;</p>
    
    <p>1>          ]</p>
  </blockquote>
  
  <p>However if I modify it to pass a pointer, everything is happy</p>
  
  <pre><code>...
          std::thread newThread(session, &amp;sock, &amp;logger);
  ...
  
  static void session(tcp::socket *sock, Log *logger)
  {
      std::cout &lt;&lt; " session () " &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><strong>Why is passing by reference calling my copy constructor</strong>. Is there something special happening here because of std::thread? Did I misunderstand the copy constructor and pass by reference?  </p>
  
  <p>I get a different but equally baffling error if I try to use std::move() as it is done in the example. Is it possible my VS2012 is not implementing C++11 correctly?</p>