I have a problem when using a vector of threads. I want to create a thread for each client in a server. So I have function called NewClient that once the connection is started, does all the necessary things for the client. This function is defined like this:
int __cdecl NewClient(SOCKET ListenSocket, SOCKET ClientSocket, char *recvbuf, int recvbuflen, int iSendResult, int iResult){
//read command from client
//execute command
//answer the server
}
And the vector of threads like this:
vector<thread> thred;
So the problem comes when I create the thread in the main using the pushback:
int __cdecl main(void) {
//things
SOCKET ListenSocket=INVALID_SOCKET;
SOCKET ClientSocket=INVALID_SOCKET;
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
int iSendResult=0;
int iResult;
thred.push_back(thread(NewClient,ListenSocket, ClientSocket, recvbuf, recvbuflen, iSendResult, iResult));
thred[thred.size()-1].detach();
}
when using(as far as I know it is used like this) :
thred.push_back(thread(NewClient,ListenSocket, ClientSocket, recvbuf, recvbuflen, iSendResult, iResult));
I get two errors, underlining thread:
Error 2 error C2661: 'std::thread::thread' : ninguna función sobrecargada acepta 7 argumentos D:\Descargas\Baaer 1.0.22\Baaer 1.0.22\Server\Server\Source_s.cpp 170 1 Server
3 IntelliSense: ninguna instancia del constructor "std::thread::thread" coincide con la lista de argumentos los tipos de argumento son: (int __cdecl (SOCKET ListenSocket, SOCKET ClientSocket, char *recvbuf, int recvbuflen, int iSendResult, int iResult), SOCKET, SOCKET, char [512], int, int, int) d:\Descargas\Baaer 1.0.22\Baaer 1.0.22\Server\Server\Source_s.cpp 170 19 Server
So how do I solve it?