title: std::Invoke, No matching overloaded function found
body: <p>I'm trying to create a thread that handles client-server communication using a socket in C++.</p>
  
  <p>The program throws an error</p>
  
  <blockquote>
    <p>std::Invoke, No matching overloaded function found</p>
    
    <p>Error C2893  Failed to specialize function template 'unknown-type std::invoke(_Callable &amp;&amp;,_Types &amp;&amp;...) noexcept(&lt;expr>)'</p>
  </blockquote>
  
  <p>I'm unable to debug the program since it crashes at startup.</p>
  
  <p>Is there anything wrong in thread initialization with two parameters? Or am I missing some library, class import?</p>
  
  <p>Can anyone help me out, what am I missing here?</p>
  
  <hr>
  
  <p>Here's my code</p>
  
  <pre><code>#include &lt;ws2tcpip.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;thread&gt;
  
  using namespace std;
  
  #pragma comment (lib, "Ws2_32.lib")
  
  #define DEFAULT_BUFLEN 512            
  PCSTR  IP_ADDRESS = "192.168.1.100";
  
  #define DEFAULT_PORT "3504"
  
  struct client_type
  {
      SOCKET socket;
      int id;
      char received_message[DEFAULT_BUFLEN];
  };
  
  int process_client(client_type&amp; new_client);
  int main();
  
  int process_client(client_type&amp; new_client)
  {
      while (1)
      {
          memset(new_client.received_message, 0, DEFAULT_BUFLEN);
  
          if (new_client.socket != 0)
          {
              int iResult = recv(new_client.socket, new_client.received_message, DEFAULT_BUFLEN, 0);
  
              if (iResult != SOCKET_ERROR)
                  cout &lt;&lt; new_client.received_message &lt;&lt; endl;
              else
              {
                  //cout &lt;&lt; "recv() failed: " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
                  break;
              }
          }
      }
  
      if (WSAGetLastError() == WSAECONNRESET)
          cout &lt;&lt; "The server has disconnected" &lt;&lt; endl;
  
      return 0;
  }
  
  int main()
  {
      WSAData wsa_data;
      struct addrinfo* result = NULL, * ptr = NULL, hints;
      string sent_message = "";
      client_type client = { INVALID_SOCKET, -1, "" };
      int iResult = 0;
      string message;
  
      cout &lt;&lt; "Starting Client...\n";
  
      // Initialize Winsock
      iResult = WSAStartup(MAKEWORD(2, 2), &amp;wsa_data);
      if (iResult != 0) {
          cout &lt;&lt; "WSAStartup() failed with error: " &lt;&lt; iResult &lt;&lt; endl;
          return 1;
      }
  
      ZeroMemory(&amp;hints, sizeof(hints));
      hints.ai_family = AF_UNSPEC;
      hints.ai_socktype = SOCK_STREAM;
      hints.ai_protocol = IPPROTO_TCP;
  
      cout &lt;&lt; "Connecting...\n";
  
      // Resolve the server address and port
      iResult = getaddrinfo(IP_ADDRESS, DEFAULT_PORT, &amp;hints, &amp;result);
      if (iResult != 0) {
          cout &lt;&lt; "getaddrinfo() failed with error: " &lt;&lt; iResult &lt;&lt; endl;
          WSACleanup();
          system("pause");
          return 1;
      }
  
      // Attempt to connect to an address until one succeeds
      for (ptr = result; ptr != NULL; ptr = ptr-&gt;ai_next) {
  
          // Create a SOCKET for connecting to server
          client.socket = socket(ptr-&gt;ai_family, ptr-&gt;ai_socktype,
              ptr-&gt;ai_protocol);
          if (client.socket == INVALID_SOCKET) {
              cout &lt;&lt; "socket() failed with error: " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
              WSACleanup();
              system("pause");
              return 1;
          }
  
          // Connect to server.
          iResult = connect(client.socket, ptr-&gt;ai_addr, (int)ptr-&gt;ai_addrlen);
          if (iResult == SOCKET_ERROR) {
              closesocket(client.socket);
              client.socket = INVALID_SOCKET;
              continue;
          }
          break;
      }
  
      freeaddrinfo(result);
  
      if (client.socket == INVALID_SOCKET) {
          cout &lt;&lt; "Unable to connect to server!" &lt;&lt; endl;
          WSACleanup();
          system("pause");
          return 1;
      }
  
      cout &lt;&lt; "Successfully Connected" &lt;&lt; endl;
  
      //Obtain id from server for this client;
      recv(client.socket, client.received_message, DEFAULT_BUFLEN, 0);
      message = client.received_message;
  
      if (message != "Server is full")
      {
          client.id = atoi(client.received_message);
  
          thread my_thread(process_client, client);
  
          while (1)
          {
              getline(cin, sent_message);
              iResult = send(client.socket, sent_message.c_str(), strlen(sent_message.c_str()), 0);
  
              if (iResult &lt;= 0)
              {
                  cout &lt;&lt; "send() failed: " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
                  break;
              }
          }
  
          //Shutdown the connection since no more data will be sent
          my_thread.detach();
      }
      else
          cout &lt;&lt; client.received_message &lt;&lt; endl;
  
      cout &lt;&lt; "Shutting down socket..." &lt;&lt; endl;
      iResult = shutdown(client.socket, SD_SEND);
      if (iResult == SOCKET_ERROR) {
          cout &lt;&lt; "shutdown() failed with error: " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
          closesocket(client.socket);
          WSACleanup();
          system("pause");
          return 1;
      }
  
      closesocket(client.socket);
      WSACleanup();
      system("pause");
      return 0;
  }```
  </code></pre>