头文件里面直接声明:
UINT ThreadFunc(LPVOID lpvoid);
这个时候会出现下面的错误:
error C2440: 'type cast' : cannot convert from '' to 'unsigned int (__cdecl *)(void *)'
None of the functions with this name in scope match the target type
原因在于线程函数在类中声明时必须是static类型的,但是一旦声明为static类型后,线程就无法访问类里面的成员变量跟成员函数了。
最后的解决办法为:
pThread = AfxBeginThread((AFX_THREADPROC)ThreadFunc, this);
将类的this指针作为线程函数传入,然后在线程函数内转换这个this指针,代码如下:
CFileFuzzView *m_pfuzzview = (CFileFuzzView *)lpvoid;
......
m_pfuzzview->m_pListCtrl->DeleteAllItems();
......
在线程函数内部通过类的this指针访问当前类的成员函数及成员变量,可以起到一样的效果。