g ++错误:pthread_create()和成员函数的指针 [英] g++ error : pthread_create() and pointer to member function
问题描述
可能重复:
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
。
不能转换 任何想法? 您需要将myFunction声明为static因为它被视为常规功能。 void(myClass :: *)(void *)
的参数3的
到
void *(*)(void *)
p>
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屋!