本文介绍了创建线程不接受成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想为网络编程创建一个类。这将创建一个通用的套接字与线程。I am trying to create a class for network programming. This will create a general purpose socket with thread.但是当我试图克隆线程使用createthread()。第三个参数产生错误。从网络我知道,我不能使用成员函数作为参数的createthread()。But when I tried to crete the thread using createthread(). The third argument is producing errors. And from the net I came to know that I can't use the member functions as an argument to the createthread().有任何事情,我可以实现Is there any thing by which I can achieve this?推荐答案在迷失的时候,我得到了,事实是,在 CreateThread socket 那么就没有麻烦了。因为 CreateThread 是套接字 。但是,如果您传递为具有套接字的对象,则套接字 不小心At lost I got it, the very fact is, in CreateThread if you pass the socket then there is no trouble. Because CreateThread is taking care of that socket. But if you pass as an object which is having that socket, then CreateThread is not taking care of the socket, and it is ends up in invalid socket in the new thread.下面成功的代码The successed code belowSOCKET s=socket(....);bind(s,...);listen(s,...);SOCKET temp=accept(s,(sockaddr *)&addrNew,&size);DWORD threadId;HANDLE thread=CreateThread(NULL,0,&MyThreadFunction,(LPVOID)(temp),0,&threadId); 这篇关于创建线程不接受成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 21:56