Search code examples
c++multithreadingargumentsbeginthreadex

Error of argument type with _beginthreadex


To define my thread I have in my Header file:

class HttpClient
{
public:
    ...
    unsigned int __stdcall  PerformLogin(void*);
    ...

};

Then in my cpp file I have:

unsigned int __stdcall PerformLogin(void*){
...
}

And to call this thread I use

hThread = (HANDLE)_beginthreadex( NULL, 0, &PerformLogin, NULL, 0, &threadID );

But i Have an error on the &PerformLogin saying that:

the args of type unsigned int (__stdcall HttpClient::)(void) is not compatible with the param unsigned int (__stdcall*)(void*).

I understand the error, but I really don't know how to fix this!


Solution

  • A possible way to fix this would be to make the member function static, though this means PerformLogin() does not have a this pointer and would have no access to non-static members of HttpClient.

    Another is to move PerformLogin() out of HttpClient altogether, and make it a free function.