1

I've searched for solutions, but after trying about 10 approaches I cannot solve my compilation issue:

 functional(1149): error C2064: term does not evaluate to a function taking 2 arguments

Here's the part of my code.

pConnectedClients.push_back(new RemoteClient(hClientSocket, RemoteClientNumber));
if (pConnectedClients.size() > 1)
{
    for (int unsigned i = 0; i < pConnectedClients.size(); i++)
    {
        if (RemoteClientRec == pConnectedClients[i]->GetNumber())
        {
            SOCKET tmp = pConnectedClients[i]->GetSocket();
            std::thread MessageThread(&cRunServer::HandleConnection, hClientSocket, &cRunServer::pConnectedClients[i]);
            MessageThread.join();
        }
    }
}

How should I pass that function correctly?

I think that it is the GetSocket() member function causing the problem...

    std::vector<RemoteClient*> pConnectedClients;

EDIT

More context:

class cRunServer : public RemoteClient {
public:
    cRunServer();
    ~cRunServer();
    void RunServer();
    void Listen(SOCKET &listeningSocket);
    void HandleConnection(SOCKET hClientSocket, SOCKET hClientSocket2);

protected:
    // Variables
    void BindAndCreate(SOCKET &listeningSocket);
    SOCKET hListeningSocket = INVALID_SOCKET;
    sockaddr_in sockAddr;
    std::vector<RemoteClient *> pConnectedClients;
    // Dane remote clienta
    // Nr clienta
    int RemoteClientNumber = 0;
    // Nr odbiorcy
    int RemoteClientRec = 0;

    // Funkcja laczy ze soba dwoch klientow

    std::string GetHostDescription(const sockaddr_in &sockAddr);
    void SetServerSockAddr(sockaddr_in *pSockAddr, int portNumber);
    void HandleMessaging(SOCKET hClientSocket, SOCKET hClientSocket2);
    void GetClientInfo(SOCKET &s);
};

// somewhere in `cRunServer::RunServer()`:  

try {
    int iResult;
    Listen(hListeningSocket);
    // Akceptujemy polaczenie
    // rzutowanie konieczne, aby moc wpisac strukture sockadrr_in do struktury sockaddr
    // Przechowywanie adresu zdalnego hosta jest opcjonalne! #wow
    hClientSocket = accept(hListeningSocket, 0, 0); //, reinterpret_cast<sockaddr*>(&clientSockAddr),&clientSockSize);
    // Sprawdzamy bledy
    if (hClientSocket == INVALID_SOCKET)
        throw Exception("accept function failed.");
    std::cout << "accepted.\n";
    GetClientInfo(hClientSocket);
    pConnectedClients.push_back(new RemoteClient(hClientSocket, RemoteClientNumber));
    if (pConnectedClients.size() > 1) {
        for (int unsigned i = 0; i < pConnectedClients.size(); i++) {
            if (RemoteClientRec == pConnectedClients[i]->GetNumber()) {
                std::thread MessageThread(&cRunServer::HandleConnection, this, hClientSocket,
                                        &cRunServer::pConnectedClients[i]);
            }
        }
    }
}

catch (Exception e)
sehe
  • 374,641
  • 47
  • 450
  • 633
reybanger
  • 123
  • 1
  • 4
  • What's the declaration of `cRunServer::HandleConnection`? What's the type of `hClientSocket`? – ildjarn Feb 11 '15 at 19:27
  • It's a little ironic that with all the code you added, you still managed to omit the part that explains where the `cRunServer` instance comes from (we can only /guess/ whether the try block is in a member function of that class...) – sehe Feb 11 '15 at 19:49
  • 1
    My bad, sorry. It is the void cRunServer::RunServer() member function. All of the functions are members of the CRunServer or RemoteClient class – reybanger Feb 11 '15 at 19:52

1 Answers1

0

std::thread MessageThread(&cRunServer::HandleConnection, hClientSocket, &cRunServer::pConnectedClients[i]);

I'm going guess that HandleConnection is a non-static member function of cRunServer and hClientSocket is not the object of cRunServer required.

Add it:

std::thread MessageThread(&cRunServer::HandleConnection, 
          this,
          hClientSocket, 
          &cRunServer::pConnectedClients[i]);

Assuming this is a cRunServer*.

See

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • @reybanger what are you saying? That's confirmation that indeed I'm right. – sehe Feb 11 '15 at 19:36
  • HandleConnection has 2 Sockets as arguments: `void HandleConnection(SOCKET hClientSocket, SOCKET hClientSocket2);` – reybanger Feb 11 '15 at 19:37
  • Sorry, I'm newbie and I cant format commants well, give me a second :) – reybanger Feb 11 '15 at 19:37
  • @reybanger Nobody can format comments well, because that's not what they're for. Code goes into the question. However, you don't need to post code in a comment. Just say/ask what you wanted to say/ask – sehe Feb 11 '15 at 19:38
  • 1
    @reybanger The point is, ***all*** non-static member functions have the implicit `this` parameter. When using `bind` you have to pass it explicitly as the first parameter. – sehe Feb 11 '15 at 19:39
  • pConnectedClients is a pointer to a vector; In the array there are objects, that have socket handles; To get that handle I need to call the pConnectedClients[i]->GetSocket() Member functions... Its just too many member functions to pass and Im lost. But what you said about this implicit this makes me thinking... – reybanger Feb 11 '15 at 19:46
  • Adding links: [how does bind work](http://stackoverflow.com/a/527983/85371), and [How to use bind with a member function](http://stackoverflow.com/questions/2304203/how-to-use-boost-bind-with-a-member-function/2304211?s=10|0.0000#2304211) – sehe Feb 11 '15 at 19:47