c++ socket线程传参数,有问题
typedefstructSParam{SOCKETst;}uParam,*sParam;SParamsparam;SParam*p;sparam.st=st;p=&sp...
typedef struct SParam
{
SOCKET st;
}uParam,*sParam;
SParam sparam;
SParam *p;
sparam.st=st;
p = &sparam;
cout<<p->st<<endl;//输出为1888
HANDLE hThread = CreateThread(NULL,0,Run,(void*)p,0,NULL);//(void*)加不加都是一样的
DWORD WINAPI Run(LPVOID lpParamter){
SParam *sparam;
sparam = (sParam)lpParamter;
//cout<<sparam->st<<endl;//没有错误,这儿输出为0,好像被强制转换转丢了 展开
{
SOCKET st;
}uParam,*sParam;
SParam sparam;
SParam *p;
sparam.st=st;
p = &sparam;
cout<<p->st<<endl;//输出为1888
HANDLE hThread = CreateThread(NULL,0,Run,(void*)p,0,NULL);//(void*)加不加都是一样的
DWORD WINAPI Run(LPVOID lpParamter){
SParam *sparam;
sparam = (sParam)lpParamter;
//cout<<sparam->st<<endl;//没有错误,这儿输出为0,好像被强制转换转丢了 展开
1个回答
2011-12-22
展开全部
st直接变成全局变量或者static的
追问
我是传socket,全局不是最优选择吧,会存在N多个变量。不是可以这样传结构体的吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询