void *function()使用c++

发布于 2025-01-25 16:55:12 字数 391 浏览 0 评论 0原文

我想使用类的对象在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尝蛊 2025-02-01 16:55:12

为了能够以Main为单位,您需要创建一个类服务器的实例来调用它。例子:

class SERVER
{
   public: 
        void *function()
        {
           return 0; //do whatever you would like in here
        }


};

int main()
{
   SERVER s1;

   s1.function(); 
}

In order to be able to call it in main, you need to create an instance of class SERVER to call it. Example:

class SERVER
{
   public: 
        void *function()
        {
           return 0; //do whatever you would like in here
        }


};

int main()
{
   SERVER s1;

   s1.function(); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文