Jun 14, 2020 at 3:43pm UTC
Hello experts!
I am using the function _beginthread to start a new thread. But its callback is static and I want to keep my processing in the class. So my question is: What is the best way to pass the object reference to the method serverProcessingInit So I can call its method serverProcessing which is not static.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef SERVER_H_
#define SERVER_H_
#include <iostream>
#include <process.h>
#include "WMap.h"
using namespace std;
class Server {
private :
WMap *wMap = NULL;
void serverProcessing();
public :
Server();
virtual ~Server();
void initialize();
static void serverProcessingInit(void *dummy);
};
#endif /* SERVER_H_ */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "Server.h"
Server::Server() {
}
Server::~Server() {
}
void Server::initialize() {
cout << "Initializing server..." << endl;
this ->wMap = new WMap();
cout << "Activating server processing. (New Thread)" << endl;
_beginthread(serverProcessingInit, 0, NULL);
cout << "Server processing active." << endl;
cout << "Activating sockets to listen to client connection" << endl;
while (true ) {
}
return ;
}
void Server::serverProcessingInit(void *dummy) {
//HERE I WANT TO CALL THE serverProcessing();
}
void Server::serverProcessing() {
cout << "in" << endl;
while (true ) {
}
}
Last edited on Jun 14, 2020 at 3:44pm UTC
Jun 14, 2020 at 4:17pm UTC
salem c, It worked perfectly. Thank you very much!