自己跟代码理解
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
class Base
{
public:
typedef DWORD (WINAPI Base::* pMemberThreadFunc)();
typedef DWORD (WINAPI * PTHREADFUNC)(LPVOID);
Base();
~Base();
public:
DWORD WINAPI ThreadFunc();
void start();
private:
HANDLE t;
int i;
pMemberThreadFunc pmem;
};
Base::Base()
{
i = 6;
pmem = ThreadFunc;
}
Base::~Base()
{
}
void Base::start()
{
PTHREADFUNC ppth;
DWORD dwAddress;
memcpy(&dwAddress,&pmem,sizeof(pmem));
memcpy(&ppth, &dwAddress, sizeof(ppth));
t = CreateThread(NULL,0,ppth,this,0,NULL);
}
DWORD WINAPI Base::ThreadFunc()
{
cout<<"i = "<<i<<endl;
return 0;
}
int main()
{
Base b;
b.start();
Sleep(2000);
return 0;
}