Hi Experts,
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
{
private:
int m_nCount;
bool status;
// function pointer
void (*ptr) (void);
HANDLE eventRun; // event for Run
HANDLE eventDie; // event for Die
HANDLE lpHandles[2];
void * baseClass; // point to the base class
public:
MyThread(int n, const char* nm, void * base);
~MyThread();
void myThreadFunction(void (*funcPtr) (void)); // (the problem method A)
void triggerEvent(EVENT e);
void initEvent();
void run();
};
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;
>> myThread->myThreadFunction(ptr);
>> myThread->start();
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.
Best regards
Ferdinand Ng