15,471
社区成员
发帖
与我相关
我的任务
分享
#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)
#include <windows.h>
#include <stdio.h>
class Class
{
public:
static int i;
static DWORD WINAPI ThreadProc( LPVOID lpParameter );
int StartThread();
};
DWORD WINAPI Class::ThreadProc( LPVOID lpParameter )
{
int j = (int)lpParameter;
// i = 2;
printf("%d\n", i);
return 0;
}
int Class::StartThread()
{
CreateThread(NULL, 0, ThreadProc, (LPVOID)2, 0, 0);
Sleep(1000);
return 0;
}
int main()
{
Class c1;
c1.StartThread();
return 0;
}
link的时候,又出错了……--------------------Configuration: Cpp1 - Win32 Debug--------------------
Linking...
Cpp1.obj : error LNK2001: unresolved external symbol "public: static int Class::i" (?i@Class@@2HA)
Debug/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
Cpp1.exe - 1 error(s), 0 warning(s)
接下来如何是好。。。