A friend sent me his threading class.
Now I just want to run a listener but the thread doesnt want to accept the function.
I want to execute the function (defined in static class Networks) THREAD listen(void* args). THREAD is a #define THREAD unsigned __stdcall
Networks::init() {
listenerth = thread();
listenerth.run(listen, NULL, "listener");
}
In class thread he defined run as void run( THREAD func(void*), void* args, const char* pname);
How can I get that to run listen in another thread either?
[edit]
Error message:
main.cpp(19): error C3867: ‘Networks::listen’: function call missing argument list; use ‘&Networks::listen’ to create a pointer to member
But when i move my mouse to the error place(symbol listen), it shows me this in a tooltip(yes, MS VC++):
unsigned int __stdcall
Networks::listen(void* data)Error: argument of type “unsigned int
(__stdcall Networks::*)(void *data)”
is incompatible with parameter of type
“unsigned int (__stdcall )(void)”
As others say, you can’t use a non-static member function here, because it expects a normal function pointer. If you need to call a non-static member (because it needs to access state in the class), then you could use the
argsargument to call it via a static “trampoline” function, something like this: