相关疑难解决方法(0)

一个类的pthread函数

假设我有一个类如

class c { 
    // ...
    void *print(void *){ cout << "Hello"; }
}
Run Code Online (Sandbox Code Playgroud)

然后我有一个c的向量

vector<c> classes; pthread_t t1;
classes.push_back(c());
classes.push_back(c());
Run Code Online (Sandbox Code Playgroud)

现在,我想创建一个线程 c.print();

以下是给我以下问题: pthread_create(&t1, NULL, &c[0].print, NULL);

错误输出:无法将'void*(tree_item :: )(void)'转换为'void*()(void)'以将参数'3'转换为'int pthread_create(pthread_t*,const pthread_attr_t*,void*()(void),void*)'

c++ pthreads

77
推荐指数
3
解决办法
10万
查看次数

pthread在c ++中创建错误

可能重复:
来自类的pthread函数

我收到一个错误("无法转换....."),我认为pthread_create调用中的第三个参数是错误的.我知道第三个参数的类型应该是(void*)*(void*)但我仍然会收到错误.

void ServerManager::Init(){  
     pthread_t thread;
     pthread_create(&thread, NULL, AcceptLoop, (void *)this);
}
Run Code Online (Sandbox Code Playgroud)

我已经这样声明了,我试着调用下面的函数

void* ServerManager::AcceptLoop(void * delegate){

}
Run Code Online (Sandbox Code Playgroud)

请让我知道如何解决这个问题..

提前致谢.

c++ pthreads

0
推荐指数
1
解决办法
1217
查看次数

标签 统计

c++ ×2

pthreads ×2