错误:void值不会被忽略,因为它应该是 [英] error: void value not ignored as it ought to be
本文介绍了错误:void值不会被忽略,因为它应该是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
的返回类型不是无效的。我缺少什么意思?
当我在main()中注释掉此调用时,错误消失。
AFAI can see, the return type of popFromVector
is NOT void. What's the point that I am missing?
The error disappears when I comment out this call in main().
推荐答案
std :: vector< T> :: pop_back()
返回void。您尝试将其作为int返回。这是不允许的。
std::vector<T>::pop_back()
returns void. You attempt to return it as an int. This is not allowed.
这篇关于错误:void值不会被忽略,因为它应该是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文