c++ - "void value not ignored as it ought to be"- 怎么了?

标签 c++ c++11

我用这种方法创建了一个类“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/

相关文章:

c++ - 如何在 GCC 5 中处理双 ABI?

c++ - 是否可以在 C++ 中使用运算符重载来更改(未修改的)包含函数的含义?

c++ - Qimage转cvMat 64FC3格式

c++ - arm-linux-gnueabihf-g++ 是否具有可靠的 C++0x 支持

c++ - 我可以在单一类型上定义可变参数模板函数吗?

c++ - 右值是否作为参数传递给函数内部的左值?

c++ - 在 C++ 中使用模板和错误

C++ While循环检查最新的输入int

c++ - 使用 C++ 创建 MAPI 配置文件

c++ - 将 const wchar_t * 转换为 const std::basic_string<char_t> 的更好方法