【发布时间】:2013-01-23 02:25:06
【问题描述】:
如果我有一个成员函数。 . .
MyClass::MyFunction()
{
while(1)
{
//blah blah blah
}
}
。 . .我尝试创建这个函数的线程。 . .
CreateThread(Null, 0, (LPTHREAD_START_ROUTINE)MyFunction, NULL, 0, NULL);
。 . .我总是收到一条错误消息,说 (LPTREAD_START_ROUTINE)MyFunction 是无效的类型转换,并且我无法创建非静态成员函数的线程。
我无法将我的函数设为静态,因为我多次使用 this 指针,这需要一个非静态成员函数。
有什么简单的方法可以创建非静态成员函数的线程吗?
(我正在使用 Visual Studio 2010、C++、MFC)
【问题讨论】:
-
这个主题在 SO 上被多次讨论。 C++ Thread in member function, Create thread is not accepting the member function, run threads of class member function in c++... 快速搜索“thread member function”会在该网站上找到很多点击。
标签: c++ multithreading mfc member-functions