我用这种方法创建了一个类“semaphore”和一个方法“reader”:
void semaforo::reader(sem_t x, sem_t y,sem_t z,sem_t rsem,sem_t wsem){
cout<<"----------------"<<endl;
cout<<"Leitor esta Lendo"<<endl;
sem_wait(&z);
sem_wait(&rsem);
sem_wait(&x);
int aux = readcountM(0);
if(aux ==1){
sem_wait(&wsem);
}
sem_post(&x);
sem_post(&rsem);
sem_post(&z);
prints(1);
sem_wait(&x);
aux = readcountN(aux);
if(aux == 0){
sem_post(&wsem);
}
sem_post(&x);
}
在我的 main.cpp 中,我创建了这些辅助变量,并将我的类实例化如下:
sem_t x,y,z,rsem,wsem;
pthread_t read[3],write[2];
thread *teste2 = new thread();
// the following line triggers the error
teste2->pthread_creation(&read[0],NULL,(void *)teste->reader(x, y, z, rsem, wsem),NULL);
有了这个我得到以下错误:
void value not ignored as it ought to be
最佳答案
您的方法“reader”返回 void。
您将该无效的返回值用作“pthread_creation”的参数。将 void 转换为指向 void 的指针(您似乎尝试过)并没有改变任何东西,更不用说它是徒劳的。
如果方法返回 void,则不能从方法返回的内容中获取值。
这就是错误/警告告诉您的内容。
关于c++ - "void value not ignored as it ought to be"- 怎么了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47731042/