0
如何將對象向量傳遞給pthread_create函數?將對象向量傳遞給pthread_create
我有這樣的代碼:
#define THREAD_NUMBER 1000
void* threadRoom (std::vector <Room*> &rooms){
some code here....
}
int main() {
std::vector <Room*> rooms;
std::vector <pthread_t> workers(THREAD_NUMBER);
pthread_create(&workers[0], NULL, threadRoom, &rooms);
return 0;
}
我真的收到這些錯誤:
error: invalid conversion from ‘void* (*)(std::vector<Room*>&)’ to ‘void* (*)(void*)’ [-fpermissive]
pthread_create(&worker[0], NULL, threadRoom, &rooms);
note: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
extern int pthread_create (pthread_t *__restrict __newthread
您正在將'rooms'的指針傳遞給'pthread_create',但您的'threadRoom'函數需要引用。 – 1201ProgramAlarm