title: Can't we use threads inside the member function of class?
body: <p>This is mine base class</p>
  
  <pre><code>class IDialysisConnector
      {
      public:
      HANDLE threadHandle_;   
      virtual int ConnectToMachine();  //This will make socket connection with the machine.
      virtual void WINAPI ServerConnectThread(LPVOID lpdwThreadParam)=0;
      };
  </code></pre>
  
  <p>Another class</p>
  
  <pre><code>class A:public IDialysisConnector
  {
  
  int ConnectToMachine()
  {
  
      int conResult,iResult;;
      struct addrinfo           *result = NULL,*ptr = NULL;
  
      u_long iMode = 0;
      DWORD nTimeout = 5000; // 5 seconds
      int port=22;
      WSADATA wsaData;
  
      // Initialize Winsock
  
      iResult = WSAStartup(MAKEWORD(2,2), &amp;wsaData);
      if (iResult != 0) 
      {
          printf("WSAStartup failed with error: %d\n", iResult);
  
      }
  
      ZeroMemory( &amp;addr_, sizeof(addr_) );
      addr_.ai_family = AF_UNSPEC;
      addr_.ai_socktype = SOCK_STREAM;
      addr_.ai_protocol = IPPROTO_TCP;
  
      // Resolve the server address and port
      conResult = getaddrinfo("192.168.15.168", (PCSTR)22, &amp;addr_, &amp;result);
      if ( conResult != 0 ) {
          printf("getaddrinfo failed with error: %d\n", conResult);
          WSACleanup();
          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
          sock_ = socket(ptr-&gt;ai_family, ptr-&gt;ai_socktype, 
              ptr-&gt;ai_protocol);
          if (sock_ == INVALID_SOCKET) {
              printf("socket failed with error: %ld\n", WSAGetLastError());
              WSACleanup();
              return 1;
          }
              conResult = ioctlsocket(sock_, FIONBIO, &amp;iMode);
          if (conResult != NO_ERROR)
              printf("ioctlsocket failed with error: %ld\n", conResult);
  
  
          conResult = setsockopt(sock_, SOL_SOCKET, SO_RCVTIMEO, (const char*)&amp;nTimeout, sizeof(DWORD));
          if (conResult != NO_ERROR)
          {
              printf("\nSetsocopt fail with error :%d\n",WSAGetLastError());
  
              return 0;
          }
  
  
          // Connect to server.
          conResult = connect(sock_, ptr-&gt;ai_addr, (int)ptr-&gt;ai_addrlen);
          if (conResult == SOCKET_ERROR) {
              closesocket(sock_);
              sock_ = INVALID_SOCKET;
              continue;
          }
          break;
      }
  
      freeaddrinfo(result);
  
      if (sock_ == INVALID_SOCKET) {
          printf("Unable to connect to server!\n");
          WSACleanup();
          return 1;
      }
      DWORD dwThreadId;
      //threadHandle_=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ServerConnectThread,this,0,&amp;dwThreadId);
          threadHandle_=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadFunc,this,0,&amp;dwThreadId);
     void WINAPI IDialysisConnector::ServerConnectThread(LPVOID lpdwThreadParam)
      {
  SOCKET ThreadSocket = INVALID_SOCKET;
      ThreadSocket=(SOCKET)lpdwThreadParam;
      while(1)
      {
          SendRequest(ThreadSocket);
          ReceiveResponse(ThreadSocket);
          Sleep(10000);
      }
          }
  </code></pre>
  
  <p>static UINT ThreadFunc(LPVOID param) {<br>
           IDialysisConnector* obj = (IDialysisConnector*)param;<br>
       obj->ServerConnectThread(); // call the member function<br>
       // to do the work in our new thread
       } </p>
  
  <pre><code>}
  
  }
  </code></pre>
  
  <p>I did like this too but same error</p>
  
  <pre><code>threadHandle_=CreateThread(NULL,0, (LPTHREAD_START_ROUTINE)IDialysisConnector::ServerConnectThread,(LPVOID)sock_,0,&amp;dwThreadId);
  </code></pre>
  
  <p>I am getting an error that is</p>
  
  <pre><code>" error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'"
  </code></pre>