关于线程函数的声明

yxliu731012 2003-04-06 02:25:58
在声明线程函数时,避免转换的麻烦,我将其声明为static UINT threadproc(LPVOID pParam),由于我将该线程函数作为类的成员函数,那么在该函数中无法使用该类的成员变量,除非将成员变量也声明为静态。请问有没有别的好的办法使得不用声明为静态也可以直接使用成员变量。
...全文
57 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
NowCan 2003-04-06
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1357/1357763.xml?temp=.9202082
http://expert.csdn.net/Expert/topic/1376/1376541.xml?temp=.1538507
http://expert.csdn.net/Expert/topic/1374/1374945.xml?temp=.7381403
http://expert.csdn.net/Expert/topic/1342/1342253.xml?temp=.8923151
http://expert.csdn.net/Expert/topic/1348/1348338.xml?temp=.6041681

哈哈,够了吧。
NowCan 2003-04-06
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1487/1487631.xml?temp=.6753351
http://expert.csdn.net/Expert/topic/1376/1376518.xml?temp=.8271295
http://expert.csdn.net/Expert/topic/1084/1084257.xml?temp=.3514978
NowCan 2003-04-06
  • 打赏
  • 举报
回复
老问题了。查旧帖吧。
一种比较适合线程的方法是,建立线程的时候把this作为CreateThread的一个参数(就是那个LPVOID型的),然后线程里就对应pParam。
static UINT threadproc(LPVOID pParam)
{
YOUR_CLASS *p=(YOUR_CLASS *)pParam;
//然后用p间接使用成员变量。

}

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧