我有一段代码,我首先定义了
std::vector<int> half_gid_m;
Run Code Online (Sandbox Code Playgroud)
我通过函数push_back计算向量half_gid_m的元素.然后我在向量上执行函数sort和unique:
sort(half_gid_m.begin(),half_gid_m.end());
std::vector<int>::iterator itv( std::unique(half_gid_m.begin(),half_gid_m.end()) );
Run Code Online (Sandbox Code Playgroud)
最后,我用重复的条目擦除向量的一部分
half_gid_m.erase(itv,half_gid_m.end());
Run Code Online (Sandbox Code Playgroud)
似乎一切都是正确的,但编译给了我这种奇怪的错误
error: no matching function for call to 'std::vector<int, std::allocator<int> >::erase(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&, __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >&) const'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = int, _Alloc = std::allocator<int>]
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = int, _Alloc = std::allocator<int>]
//home/gales/ingv/p-gales/simulations/little_mesh/lib/p-gales/include/gales-0.1/gales/map/map_rule.hpp:166: …
Run Code Online (Sandbox Code Playgroud)