/*
线程函数如果声明在类中, 则需要静态函数.
否则普通函数中将压入this参数 .
所以在类中先声明一个静态函数,用于线程的启动.
再写一个虚函数 run , 在线程中调用, 也可以用于子类的重写
*/
class ThreadObject{
public:
ThreadObject() : m_thread(NULL), m_threadId(0){
}
void startThread(){
m_thread = (HANDLE)_beginthreadex(NULL,
0,
ThreadObject::thread_func, //静态函数
(void*)this, //把this指针传入线程
0,
&m_threadId);
if(m_thread)
cout << "lauched , tid:" << m_threadId << endl;
else
cout << "error : " << GetLastError() << endl;
}