void *function()使用c++
我想使用类的对象在main内部调用void *函数。
class SERVER{
public:
void *handle_client(void *arg){
...
}
};
int main(){
SERVER s1;
pthread_create(&tid, NULL, &handle_client, (void*)cli);
//how to call handle_client using s1 object
}
函数在pthread.h中预定了。
呼叫 const pthread_attr_t *限制attr, void *( *start_routine)(void *), void *限制arg);
I want to call the void *function inside main using the object of the class
class SERVER{
public:
void *handle_client(void *arg){
...
}
};
int main(){
SERVER s1;
pthread_create(&tid, NULL, &handle_client, (void*)cli);
//how to call handle_client using s1 object
}
The calling function is predefined in pthread.h and the syntax is:
int pthread_create(pthread_t *restrict thread,
const pthread_attr_t *restrict attr,
void *(*start_routine)(void *),
void *restrict arg);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了能够以Main为单位,您需要创建一个类服务器的实例来调用它。例子:
In order to be able to call it in main, you need to create an instance of class SERVER to call it. Example: