您的位置:首页 > 其它

类中使用线程例子5

2015-05-05 22:41 393 查看
#include <stdio.h>
#include <process.h>
#include <windows.h>

//前置声明
class A;

struct studen
{
	A* pa;
};

class A
{
public:
	void test(void){abc=123;printf("test\n");}
	void StartThread();
	DWORD static WINAPI ThreadFunc(LPVOID lparam);
public:
	int abc;
};

void A::StartThread()
{
	studen p;
	p.pa=this;
	CreateThread(NULL,NULL,ThreadFunc,&p,NULL,NULL);
}

DWORD  WINAPI A::ThreadFunc( LPVOID lparam )
{
	A* pa=static_cast<A*>(lparam);

	pa->test();
	printf("%d\n",pa->abc);
	return true;

}

int main (void)
{

	A a;
	a.StartThread();
	getchar();
	return 0;
}
/*
2015年5月5日 22:42:03
程序执行结果如下:
test
123

请按任意键继续. . .

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: