类中使用线程例子5

来源:互联网 发布:时空错乱事件知乎 编辑:程序博客网 时间:2024/06/03 17:39
#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程序执行结果如下:test123请按任意键继续. . .*/

0 0