i\'m trying to create a new thread with a class \"CameraManager\" but i have the following error:
cannot convert \'*void(CameraManager:: * )(void*) to
If you want the function to be a member of the class, it must be static
. It's because the thread function will be called directly and will not have a valid this
pointer. This can be solved by having a wrapper function, that gets passed the actual object and then calls the proper member function:
void *dequeueLoopWrapper(void *p)
{
CameraManager *cameraManager = static_cast(p);
camereraManager->dequeueLoop();
return nullptr;
}
// ...
void CameraManager::startDequeuing()
{
dequeuing = true;
dequeueThreadId = pthread_create(&dequeueThread, NULL, dequeueLoopWrapper, this);
}
However, I would recommend you start using the threading support in the new standard library:
void CameraManager::startDequeuing()
{
dequeuing = true;
myThread = std::thread(&CameraManager::dequeueLoop, this);
}