小编Gab*_*tto的帖子

无法在pthread_create函数中将'*void(MyClass ::*)(void*)转换为void*(*)(void*)

我正在尝试使用类"CameraManager"创建一个新线程,但我有以下错误:

无法在pthread_create函数中将'*void(CameraManager ::*)(void*)转换为void*(*)(void*)

我在cameramanager.h文件中定义:

public:
void *dequeueLoop(void *ptr);
Run Code Online (Sandbox Code Playgroud)

并在cameramanager.cpp

void CameraManager::startDequeuing(){
dequeuing = true;
dequeueThreadId = pthread_create(&dequeueThread, NULL, &CameraManager::dequeueLoop, NULL);
}

void *CameraManager::dequeueLoop(void *ptr){
while(dequeuing){
    highSpeedCamera->dequeue();
    highSpeedCamera->enqueue();
}
Run Code Online (Sandbox Code Playgroud)

我不想将dequeueLoop声明为静态函数我也尝试以下列方式将dequeueLoop声明为类友元函数但是它没有类变量'highSpeedCamera'和'dequeuing'的范围,编译器也告诉我我认为'dequeueLoop'未在此范围内声明

使dequeueLoop成为朋友的功能我做了:

cameramanager.h

public:
friend void *dequeueLoop(void *ptr);
Run Code Online (Sandbox Code Playgroud)

cameramanager.cpp

void CameraManager::startDequeuing(){
    dequeuing = true;
    dequeueThreadId = pthread_create(&dequeueThread, NULL, &CameraManager::dequeueLoop, NULL);
}
void *dequeueLoop(void *ptr){
    while(dequeuing){
        highSpeedCamera->dequeue();
        highSpeedCamera->enqueue();
    }
}
Run Code Online (Sandbox Code Playgroud)

哪里我做错了?

c++ pthreads friend friend-function

5
推荐指数
1
解决办法
3935
查看次数

标签 统计

c++ ×1

friend ×1

friend-function ×1

pthreads ×1