求教,C++类中创建线程函数的问题
麻烦各位高手了,还望赐教。
有一个类,两个函数。一个函数是线程函数:
#include <windows.h>
#include <stdio.h>
class Class
{
public:
int i;
DWORD WINAPI ThreadProc( LPVOID lpParameter );
int StartThread();
};
DWORD WINAPI Class::ThreadProc( LPVOID lpParameter )
{
int j = (int)lpParameter;
printf("%d + %d = %d\n", i, j, i + j);
return 0;
}
int Class::StartThread()
{
CreateThread(NULL, 0, ThreadProc, (LPVOID)123, 0, 0);
}
int main()
{
Class c1;
c1.StartThread();
return 0;
}
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\System\桌面\Cpp1.cpp(27) : error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
Cpp1.obj - 1 error(s), 0 warning(s)
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\System\桌面\Cpp1.cpp(20) : error C2597: illegal reference to data member 'Class::i' in a static member function
D:\System\桌面\Cpp1.cpp(20) : error C2597: illegal reference to data member 'Class::i' in a static member function
执行 cl.exe 时出错.
Cpp1.obj - 1 error(s), 0 warning(s)