我正在尝试根据C ++ 17标准编译简单的代码:
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
int main() {
vector<int> numbers = {6, 1, 3, 9, 1, 9, 8, 12, 1};
vector<int> res;
copy(begin(numbers), end(numbers), make_move_iterator(back_inserter(res)));
return 0;
}
[此刻make_move_iterator(back_inserter(res))
,我得到一个错误。
错误开始((我认为不包括无意义的后续信息):
In file included from C:/Users/Name/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:67,
from C:/Users/Name/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/algorithm:61,
from C:\Users\Name\CLionProjects\coursera_cpp_course3\week5\c3_w5_t6_merge_sort_3\c3_w5_t6_merge_sort_3.cpp:2:
C:/Users/Name/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h: In instantiation of 'class std::move_iterator<std::back_insert_iterator<std::vector<int> > >':
C:\Users\Name\CLionProjects\coursera_cpp_course3\week5\c3_w5_t6_merge_sort_3\c3_w5_t6_merge_sort_3.cpp:49:77: required from here
C:/Users/Name/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:1023:24: error: forming reference to void
__base_ref>::type reference;
^~~~~~~~~
我已经读过documentation on make_move_iterator(),并且在这里没有看到使用它的任何先决条件。
为什么会发生?谢谢您的建议。
我尝试编译的条件:
Windows 10
MinGW 8.1.0
CMake 3.17.1