我想在下面的代碼中創建一個線程,但指向pthread_create方法調用的函數參數的指針只是不讓我編譯我的代碼。pthread_create參數函數指針
請讓我知道我做錯了,我怎麼能解決這個問題在下面的代碼:
#include "RobotNodes.cpp"
int main(int argc, char** argv){
int i, numRobotsToInit = 7;
//declare run function pointer
void (*run)();
//create array of robot nodes
RobotNodes* robots[numRobotsToInit];
//init robot nodes
for(i = 0; i<numRobotsToInit; i++){
robots[i] = new RobotNodes(i, 0.2, 0.2);
}
for(i = 0; i<numRobotsToInit; i++){
run = &robots[i]->run;
pthread_t thread;
pthread_create(&thread, NULL, (void*(*)(void*))run, NULL);
}
}
的錯誤,我得到的是這樣的: error: lvalue required as unary ‘&’ operand
編輯:運行( )是類RobotNodes.cpp中的一個方法,該類包含在此類的頂部。
您確定您沒有將免費功能與會員功能混淆嗎? –