title: C++ difference between function declaration and object initialization
body: <p>If i wrote this line of code:</p>
  
  <pre><code>std::thread t(EchoServer(socket));
  </code></pre>
  
  <p>How can the compiler interpret this instruction? It can be a function declaration or simply an initialization.
  I've the followinc code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;boost/asio.hpp&gt;
  
  #include &lt;boost/asio.hpp&gt;
  
  typedef boost::asio::ip::tcp::socket Socket;
  auto socket_deleter = [] (Socket* s) {s-&gt;close(); delete s;};
  typedef std::unique_ptr&lt;Socket, decltype(socket_deleter)&gt; socket_ptr;
  
  class EchoServer {
  public:
      static void Listen(unsigned int port)
      {
  
          using namespace std;
          using namespace boost::asio;
  
          io_service ios;
  
          // create an endpoint to listen to a certain port
          ip::tcp::endpoint endpoint(ip::tcp::v4(), port);
  
          cout &lt;&lt; "Listening to TCP Socket on port " &lt;&lt; port &lt;&lt; " ..." &lt;&lt; endl;
  
          // Start opening a socket
          ip::tcp::acceptor acceptor(ios, endpoint);
  
          // this loop must be infinite... but we accept only 3 connections
          auto socket = socket_ptr(new Socket(ios));
  
          std::thread t(EchoServer(socket));
      }
  
      EchoServer(socket_ptr&amp;&amp; s) : m_socket(std::move(s))
      {
      }
  
      void operator ()() const
      {
      }
  
  private:
      socket_ptr m_socket;
  };
  </code></pre>
  
  <p>But the compiler give me the following warning:</p>
  
  <pre><code>C4930: 'std::thread t(EchoServer(socket))': std::thread t(EchoServer(socket)) function not called (was a variable definition intended?).
  </code></pre>
  
  <p>So how can I explain that this line is an object of type std::thread creation instead a function declaration.</p>
  
  <p><strong>UPDATE 1:</strong>
  I'm using visual studio 2012 that don't support uniform initialization so I've changed the code from <code>std::thread t((EchoServer(socket)));</code> to <code>std::thread t((EchoServer(socket)));</code> but this time I've a compil time error that i don't understand:</p>
  
  <pre><code>error C2440: '&lt;function-style-cast&gt;': cannot convert from 'std::unique_ptr&lt;_Ty,_Dx&gt;' to 'EchoServer'
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p><strong>UPDATE 2</strong>
  I've probably have to understand better move-semantic the problem is with the declaration of socket_ptr. I've changed the code in this (ugly) way... but now compiles.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;boost/asio.hpp&gt;
  
  typedef boost::asio::ip::tcp::socket Socket;
  auto socket_deleter = [] (Socket* s) {s-&gt;close(); delete s;};
  /*
  typedef std::unique_ptr&lt;Socket, decltype(socket_deleter)&gt; socket_ptr;
  */
  typedef Socket* socket_ptr;
  
  class EchoServer {
  public:
      static void Listen(unsigned int port)
      {
  
          using namespace std;
          using namespace boost::asio;
  
          io_service ios;
  
          // create an endpoint to listen to a certain port
          ip::tcp::endpoint endpoint(ip::tcp::v4(), port);
  
          cout &lt;&lt; "Listening to TCP Socket on port " &lt;&lt; port &lt;&lt; " ..." &lt;&lt; endl;
  
          // Start opening a socket
          ip::tcp::acceptor acceptor(ios, endpoint);
  
          // this loop must be infinite... but we accept only 3 connections
          auto socket = new Socket(ios);
  
          std::thread t((EchoServer(socket)));
      }
  
      EchoServer(socket_ptr s) : m_socket(s)
      {
      }
  
      ~EchoServer()
      {
          m_socket-&gt;close();
          delete m_socket;
      }
  
      void operator ()() const
      {
      }
  
  private:
      socket_ptr m_socket;
  };
  </code></pre>
  
  <p>Changine socket_ptr as a simple pointer instead of an unique_ptr the code works.</p>