类中使用线程例子4

来源:互联网 发布:时空错乱事件知乎 编辑:程序博客网 时间:2024/06/06 12:57
#include <stdio.h>#include <process.h>#include <windows.h>class A{public:void StartThread();DWORD static WINAPI ThreadFunc(LPVOID lparam);public:int abc;};void A::StartThread(){CreateThread(NULL,NULL,ThreadFunc,this,NULL,NULL);}DWORD  WINAPI A::ThreadFunc( LPVOID lparam ){A* pa=(A*)lparam;pa->abc=123;printf("%d\n",pa->abc);return true;}int main (void){A a;a.StartThread();getchar();return 0;}/*2015年5月5日 22:39:46程序执行结果如下:123请按任意键继续. . .*/

0 0