Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Question on function pointer?
I am implementing a thread which consist will call the pass in function (using function pointer) continueously.
My thread class is the following:
lass MyThread : public Thread
// function pointer
void (*ptr) (void);
HANDLE eventRun; // event for Run
HANDLE eventDie; // event for Die
void * baseClass; // point to the base class
MyThread(int n, const char* nm, void * base);
void myThreadFunction(void (*funcPtr) (void)); // (the problem method A)
void triggerEvent(EVENT e);
When I create the thread object, I will pass in a function pointer like this:
>> myThread = new MyThread(1, "MyListener", this);
>> void (CMyNetwork::*ptr) (void);
>> ptr = &CMyNetwork::listenerMethod;
where listenerMethod is defined like this:
>> void listenerMethod(void);
I realize that the problem error is wrong, since my function pointer is pointing to an member function of the class CMyNetwork::listenerMethod, but I want the thread object independent to the network (cause of the two class linking to each other). Is there solution for my problem.
Or if there is an alternative way to implement that.
Thank you very much for reading this post.