繁体   English   中英

C++17 无匹配 function 用于调用以减少错误

[英]C++17 no matching function for call to reduce error

此代码来自 Apress 的C++17 标准库快速参考书

#include <numeric>
#include <vector>

using namespace std;
int main() {
  vector vec {4,2,5,1,3,6};
  int sum = reduce( begin(vec), end(vec));
}

当我使用Windows 7上的选项-std=c++17 (或-std=gnu++2a )使用g++-9.2编译它时,我得到:

error: no matching function for call to 'reduce(std::vector<int, std::allocator<int> >::iterator, std::vector<int, std::allocator<int> >::iterator)'

这段代码有什么问题? 谢谢你。

正如另一条评论已经指出的那样,我尝试使用x86-64 gcc (contracts)版本编译您的代码,我想这是 gcc 编译器的实验版本,并且编译成功。 在这里试试。

此外,我在Reddit上遇到了一篇有趣的帖子,主题与我们在这里讨论的主题相同。

编辑

正如 OP 在下面的评论中发布的那样, gcc-10.0.0成功地编译了问题中的代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM