pointers to functions/member functions
I am at the moment writing a multithreaded server (what kind of server, is not relevant) using the pthread library.
I want to encapsulate some of the c code into c++ classes and instead of using a ordinary function as I would usually use as the running thread function, I want to use a member function.
Here comes my problem. When you want to spawn new threads you usually just do something like this:
handler.cpp: In method `void HandlerThread::start()':
handler.cpp:51: no matches converting function `thread_func' to type `void * (*)(void *)'
handler.cpp:43: candidates are: void * HandlerThread::thread_func(void *)
The pthread_create function takes as its third parameter a pointer to a function that takes a void pointer and returns a void pointer.
There is problem casting to a pointer to function when I really got
a member function. Maybe this is not possible. If not, I hope someone have any suggestions
Hope you understood my problem
The member functions that you are pointing to need to be static methods, or else global functions, or else you need to encasulate the object being used inside an adapter because local class methods require the object instance.
thanks, it worked great using a static method
|All times are GMT -5. The time now is 09:21 PM.|