【发布时间】:2013-10-05 18:50:58
【问题描述】:
我需要通过线程调用一个类的成员函数,但我不想使用 Boost 库绑定概念,而且我必须使用的类没有任何静态函数来提供帮助。我尝试使用STL mem_fun_ref,但收到编译时错误。
base b;
handle = CreateThread(NULL, 0, LPTHREAD_START_ROUTINE(bind2nd(mem_fun_ref(&base::show), &b)),
NULL, NULL, &dword);
class B{
public:
void show(){
cout << "show";
}
};
【问题讨论】:
-
你得到的两个答案都是对的,但是注意一般应该使用
_beginthreadex()而不是CreateThread(),否则CRT可能无法为新线程正确初始化。
标签: c++ multithreading visual-studio winapi