c++ - 错误 : void value not ignored as it ought to be

标签 c++ vector

template <typename Z> Z myTemplate <Z> :: popFromVector ()
{
    if (myVector.empty () == false)
        return myVector.pop_back ();

    return 0;
}

int main ()
{
    myTemplate <int> obj;

    std :: cout << obj.popFromVector();

    return 0;
}

错误:

error: void value not ignored as it ought to be

AFAI 可以看到,popFromVector 的返回类型不是 void。我错过了什么? 当我在 main() 中注释掉这个调用时,错误消失了。

最佳答案

std::vector<T>::pop_back()返回无效。您尝试将其作为 int 返回。这是不允许的。

关于c++ - 错误 : void value not ignored as it ought to be,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7307830/

相关文章:

c++ - Getline 只返回空白

c++ - 当 vector 存储在 RAM 中时,变量到底存储在哪里?

Java Vector : Each element contains three objects. 如何根据其中之一的值进行操作?

c++ - 插槽被意外调用

C++ 结构数组 Win Form 损坏

C++ msgsnd 和 msgrcv 陷休眠眠

c++ - 用作一维的多维 vector 的迭代器?

c++ - 使用两个标准对对象 vector 进行排序

虚拟基函数的 c++ 调用被忽略

c++ - 有没有一种安全的方法可以在 C++ 中执行来自用户/客户端的代码?