c++ - g++ 错误 : pthread_create() and pointer to member function

标签 c++ pthreads iso

<分区>

Possible Duplicate:
pthread Function from a Class

我正在尝试创建一个带有启动例程的线程,但 g++ 不喜欢我的语法。

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);
  }
}

在编译器期间,g++ 告诉我 ISO C++ 禁止采用未限定或带括号的非静态成员函数的地址来形成指向成员函数的指针。说“&myFunction”

对于 pthread_create< 的参数 3,它无法将 void (myClass::*) (void*) 转换为 void* (*) (void*)/.

有什么想法吗?

最佳答案

您需要将 myFunction 声明为 static 才能将其视为常规函数。

关于c++ - g++ 错误 : pthread_create() and pointer to member function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12975232/

相关文章:

c - 在多线程程序中处理异步信号

c - 多个线程如何更改互斥锁锁定的静态变量

iso - ISO 8583 的完整声明

Python csv.reader 自动转换 ISO 日期?

c++ - 使用 C++ 处理 GPIO 按钮事件

c++ - 如何在 OpenCV 中将 4 维矩阵转换为 NHWC 格式

c++ - 使用 gtest 为动态库编写单元测试

c++ - 为什么采用 std::initializer_list 的构造函数不首选双花括号语法

c - 如何通过pthread管理两个或更多的使用者?

prolog - Prolog 的序言?