Here is my code kindly tell me how to resolve this error. both functions are methods of the class.
void* make_desc(void* arg){
int *k;
k = (int *) arg;
Node* tt;
int i,j;
//for(int k=0;k<4;k++){
int c[16],t[2];
//tr is in the begin of the code, used for going, up,down,left or rigth
i=this->zero[0]+tr[(*k)].first;
j=this->zero[1]+tr[(*k)].second;
if(i>=0 && i<4 && j>=0 && j<4){
cp(this->array,c);
c[this->zero[0]*4+this->zero[1]]=c[i*4+j];
c[i*4+j]=0;
t[0]=i;
t[1]=j;
//check if note already seen, if not seen add
//if seen but depth is smaller than previous, add also
if(setx.find(myhash(c))==setx.end()){
Node *tt = new Node(c,t,this->depth+1,this->path);
//l.push_back(tt);
}
else if(setx[myhash(c)]>this->depth+1){
setx[myhash(c)]=this->depth+1;
Node *tt = new Node(c,t,this->depth+1,this->path);
//l.push_back(tt);
}
}
pthread_exit(tt);
//return tt;
// return l;
// }
}
vector<Node*> threads(){
vector<Node*> l;
Node* ret;
int j=0;
for(int i=0;i<4;i++){
j=i;
pthread_create(&th[i],NULL,make_desc,(void*)&j);
}
//ERROR
main.cpp: In member function ‘void Node::Make_threads()’:
main.cpp:208:54: error: invalid use of non-static member function ‘void* Node::make_desc(void*)’
pthread_create(&th[i],NULL,make_desc,NULL);
^
main.cpp:169:11: note: declared here
void* make_desc(void* arg) {
^~~~~~~~~
main.cpp: In function ‘bool A_star_Manhattan()’:
main.cpp:272:58: error: no matching function for call to ‘Node::make_desc()’
vector<Node *> dsc = current_node->make_desc();
^
main.cpp:169:11: note: candidate: void* Node::make_desc(void*)
void* make_desc(void* arg) {
^~~~~~~~~
main.cpp:169:11: note: candidate expects 1 argument, 0 provided***
Using the pthread
library, the argument function can not be a member of a class. You have to define it separately outside everything.
argument of type "void *(myclass::*)()" is incompatible with parameter of type "void *(*)(void *)"C/C++(167)
As I can see, you are using C++ , and I highly recommend you to check C++ multithreading. link The syntax is much simpler, and everything is implemented using pthread
behind the scenes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.