
问题
可能重复:
来自类的pthread函数
我正在尝试使用启动例程创建线程,但是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);
}
}
在编译器中pthread_create 函数指针,g ++告诉我ISO C ++禁止采用不合格或带括号的非静态成员函数的地址来形成指向成员函数的指针. 说“&myFunction”.
它无法将pthread_create的参数3的void(myClass :: *)(void *)转换为void *(*)(void *).
有什么主意吗?

解决方案
您需要将myFunction声明为静态函数,才能将其视为常规函数.
本文地址: IT之家»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);
}
}

在编译器中pthread_create 函数指针,g ++告诉我ISO C ++禁止获取不合格或带括号的非静态成员函数的地址以形成指向成员函数的指针. 说明和myFunction.
无法转换void(myClass :: *)(void *)
有什么想法吗?
解决方案
您需要将myFunction声明为静态,因为它被视为常规函数.
本文地址: IT之家»g ++错误: pthread_create()和指向成员函数的指针
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-178256-1.html
对美国只有一句话
如果没有蛆
伊拉克依靠美国反恐只能越反越恐
不要有丝毫留情