g ++错误:pthread_create()和成员函数的指针 [英] g++ error : pthread_create() and pointer to member function

查看:294
本文介绍了g ++错误:pthread_create()和成员函数的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

pthread函数从类


一个有启动例程的线程,但是g ++不喜欢我的语法。

  class myClass 
{
void * myFunction(void * myArg)
{
//一些代码,无用的在这里
}

void start()
{
pthread_t thread_id;
int * fd;

//有些代码,在这里没用。

pthread_create(& thread_id,0,& myFunction,(void *)fd);
}
}

在编译器中,g ++告诉我 ISO C ++禁止获取非限定或括号非静态成员函数的地址,以形成指向成员函数的指针。说明& myFunction



不能转换 void(myClass :: *)(void *)的参数3的 void *(*)(void *) p>

任何想法?

解决方案

您需要将myFunction声明为static因为它被视为常规功能。


Possible Duplicate:
pthread Function from a Class

I am trying to create a thread with a start routine, but g++ does not like my syntax.

class myClass
{
  void* myFunction(void* myArg)
  {
    // some code, useless here
  }

  void start()
  {
    pthread_t thread_id;
    int* fd;

    //Some code, useless here.

    pthread_create(&thread_id, 0, &myFunction, (void*) fd);
  }
}

During compilator, g++ tells me that ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&myFunction'.

It cannot convert void (myClass::*) (void*) to void* (*) (void*) for argument 3 of pthread_create.

Any idea ?

解决方案

You'll need to declare myFunction as static for it to be treated as a regular function.

这篇关于g ++错误:pthread_create()和成员函数的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆