要定义我的头文件中的线程:
class HttpClient
{
public:
...
unsigned int __stdcall PerformLogin(void*);
...
};
然后在我的 cpp 文件中我有:
unsigned int __stdcall PerformLogin(void*){
...
}
并调用我使用的线程
hThread = (HANDLE)_beginthreadex( NULL, 0, &PerformLogin, NULL, 0, &threadID );
但是我在 &PerformLogin
上有一个错误说:
the args of type unsigned int (__stdcall HttpClient::)(void) is not compatible with the param unsigned int (__stdcall*)(void*).
我明白这个错误,但我真的不知道如何解决这个问题!
最佳答案
解决此问题的一种可能方法是使成员函数static
,尽管这意味着PerformLogin()
没有this
指针,并且无法访问 HttpClient
的非静态成员。
另一种方法是将 PerformLogin()
完全从 HttpClient
中移出,并使其成为一个免费函数。
关于c++ - _beginthreadex 的参数类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11289855/