我使用CreateThread 函数在 C++中编写了一个类似C# BackgroundWorker的类。我的代码:
背景工作者.h:
class BackgroundWorker
{
private :
HANDLE _threadHandle;
unsigned int _threadCallcounter;
DWORD _threadID;
public:
BackgroundWorker();
~BackgroundWorker();
virtual DWORD WINAPI Function(LPVOID vpPram);
}
BackgroundWorker.cpp:
#include "BackgroundWorker.h"
void BackgroundWorker::DoWork()
{
this->_threadHandle = CreateThread(NULL,
0,this->Function,&this->_threadCallcounter,
0, &this->_threadID); // !!!***This part throws an error***!!!
}
然后我创建了另一个派生自 BackgroundWorker 的类:
听线程.cpp:
class ListenThread :public BackgroundWorker
{
DWORD WINAPI Function(LPVOID vpPram)
{
//DO somthing...
return 0;
}
};
但是该行给了我以下错误:
非标准语法;使用 '&' 创建指向成员的指针