我想在一个类中实现如下的代码,该怎么办
因为beginthead的第一个参数是_cdecl*的,不知道怎么强制转换,
各位给点意见阿
class a
{
 public void func(void *p);
 public void startThread();
}void a::startThread()
{
  beginthread(func,0,NULL);
}

解决方案 »

  1.   


    func
    声明成static型的函数
      

  2.   

    类普通成员函数有一个默认的this指针作参数,所以同楼上所说应用static类型成员函数。
      

  3.   

    msdn上的例子#include <windows.h>
    #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就可以了
      

  4.   

    类的成员函数都是thiscall,向使用beginthread就要生命成_cdecl类型的静态函数,另外最好用beginthreadex创建线程,本人的blog有篇小文介绍了beginthread,beginthreadex和createthread的区别