一个创建线程的问题

tmp.hpp

class CCommun
{
  ...
  public:
  bool createthread(void);
  void run(void);
  static void * entry(void *p);
  private:
  pthread_t m_threadhandle;
  ....
}


tmp.cpp

bool CCommun::createthread(void)
{
  int i_ret;
  i_ret= pthread_create(&m_threadhandle,null,entry,(void*)this);
  if(i_ret!=0)
  return 0;
  return 1;

}
void CCommun::run(void)
{
  while(!b_exit)
  sleep(1000);
}
void* CCommun:: entry(void *p)
{
return ((CCommun *)p)->run();
return (void*)0;
}

谁能给我说一下,上面代码中的 (void *)this , (void*)0, 以及entry定义加static的作用

作者: tottili   发布时间: 2011-04-29

(void *)this , (void*)0
加强制转换是因为参数需要是void*
static表示该方法是所有对象共享的,通过类名就可以调用

作者: thefirstz   发布时间: 2011-04-29

加static 是静态成员函数,不能访问类中的非静态成员

作者: justkk   发布时间: 2011-04-29