Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a thread class at vs2005
C++
m_hThread = (HANDLE)_beginthreadex(NULL,0, CThreadClass::start_address, this, 0,  &m_Thraddr)

There is a error C3867:
"CThreadClass::start_address": function lost function list.


C++
Unsigned CThreadClass::start_address(void* obj)
{ 
  return FALSE; 
}


Could you tell me how can I cover this error?

I referee from the blog http://www.cppblog.com/API/archive/2011/03/11/141563.html[^]

But I don't want a static class function.
Posted
Updated 3-Jun-15 23:33pm
v4

You can't pass a pointer to a member function as the routine to the _beginthread() function. The function requires a pointer to a global or static function.
 
Share this answer
 
Thread functions must be static. But you can use a static wrapper function that calls a non-static member function when passing a pointer to your class:
CThreadClass
{
    // ...
    void start_thread();
private::
    // Static thread function
    unsigned __stdcall start_address(void* obj);
    // Non-static function called from static version
    unsigned thread_func();
};

C++
void CThreadClass::start_thread()
{
    m_hThread = (HANDLE)_beginthreadex(NULL,0, &CThreadClass::start_address, this, 0,  &m_Thraddr);
}

// Static thread function
unsigned CThreadClass::start_address(void* obj)
{
    CThreadClass *p = (CThreadClass *)obj;
    return p->thread_func();
}

// Non-static function called from static thread function
unsigned CThreadClass::thread_func()
{
    // Do your work here using the class's member variables and functions
    return FALSE;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900