I am trying to create a thread in the following code but the pointer to a function parameter of the pthread_create method call is just not letting me compile my code.
Please let me know what I am doing wrong and how can I fix it in the following code:
#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);
}
}
The error that I get is the following:
error: lvalue required as unary ‘&’ operand
Edit: run() is a method from class RobotNodes.cpp that is included on the top of this class.