我想在一个类中实现如下的代码,该怎么办
因为beginthead的第一个参数是_cdecl*的,不知道怎么强制转换,
各位给点意见阿
class a
{
public void func(void *p);
public void startThread();
}void a::startThread()
{
beginthread(func,0,NULL);
}
因为beginthead的第一个参数是_cdecl*的,不知道怎么强制转换,
各位给点意见阿
class a
{
public void func(void *p);
public void startThread();
}void a::startThread()
{
beginthread(func,0,NULL);
}
func
声明成static型的函数
#include <stdio.h>
#include <process.h>unsigned Counter;unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...\n" ); while ( Counter < 1000000 )
Counter++; _endthreadex( 0 );
return 0;
}void main()
{
HANDLE hThread;
unsigned threadID; printf( "Creating second thread...\n" ); // Create the second thread. hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0,
&threadID ); // Wait until second thread has terminated. If you comment out the line
// below, Counter will not be correct because the thread has not
// terminated, and Counter most likely has not been incremented to
// 1000000 yet. WaitForSingleObject( hThread, INFINITE ); printf( "Counter should be 1000000; it is-> %d\n", Counter ); // Destroy the thread object. CloseHandle( hThread );
} 这里你是在类里声明的
只要把你的线程函数声明为static就可以了