我有以下:奇怪C++线程功能调用
class DThread
{
virtual void run()=0;
_beginthreadex(NULL,0,tfunc,this,0,&m_UIThreadID); // class itself being passed as param to thread function...
static unsigned int __stdcall tfunc(void* thisptr)
{
static_cast<DThread*>(thisptr)->run();
return 0;
}
//other stuff
}
的运行功能由派生类中实现。
为什么在线程中被调用的函数被通过铸造this
指针调用?这是好的做法吗?
不能直接调用吗?
需要运行的实际功能在派生类中。
我的问题是
你的问题是...? – Anthony 2010-05-17 12:22:45
为什么在线程中调用的函数是通过强制转换这个指针来调用的?这是好的做法吗? 不能直接调用吗? – 2010-05-17 12:23:26
静态成员函数中没有“this”。 – eemz 2010-05-17 12:38:23