【发布时间】:2019-05-12 15:02:55
【问题描述】:
我正在尝试使用需要两个迭代器的 std::reverse 来反转数组的一部分。当我尝试如下构造迭代器时:
int a[] = {0, 1, 2, 3, 4, 5, 6};
reverse(begin(a + 2), end(a + 4));
我收到一个错误:
template argument deduction/substitution failed:
test.cpp:8:33: note: mismatched types ‘const std::valarray<_Tp>’ and ‘int*’ reverse(begin(a + 2), end(a + 4));
构造迭代器的正确方法是什么?
【问题讨论】:
-
我想我找到了一种反转元素的方法,我只需要做 reverse(a+2, a+4);
-
但我仍然很好奇如何让错误消失。
-
您自己说过如何让它消失 - 摆脱错误且不应该存在的
begin和end调用。