있습니다. 나는 여기에서 내 질문을 검색했지만 관련성이있는 것을 찾지 못했습니다. 이것이 문제입니다.
나는이 코드를 내 프로그램에서 삽입에 의한 어리석은 정렬을하고있다.
나는 MSVS 2008에서 그것을 개발했고 모두 잘 동작했지만, g ++로 컴파일하려고했을 때 아래의 list::insert
함수 때문에 실패했다.stl vector :: Windows와 Linux의 차이점을 삽입 하시겠습니까?
//...
pair<uint, double> NewElem(i, Prob.at(i));
bool inserted(false);
vector<pair<uint, double> >::const_iterator li = NewList.begin();
for (vector<double>::const_iterator ji = BlocksMemory.begin() ; ji != BlocksMemory.end() ; ++ji)
{
if (NewElem.second <= *ji)
li += _SORT_BLOCK;
else
break;
}
for(;li != NewList.end() ; ++li)
{
if (NewElem.second > li->second)
{
NewList.insert(li, NewElem);
inserted = true;
break;
}
}
하나시피 li
의 NewList
는 const_iterator
이고; NewElem
의 유형은 NewList
콘텐츠와 동일한 유형 인 pair
입니다.
main.cpp:447: error: no matching function for call to "
std::vector<std::pair<unsigned int, double>, std::allocator<std::pair<unsigned int, double> > >::insert(__gnu_cxx::__normal_iterator<const std::pair<unsigned int, double>*, std::vector<std::pair<unsigned int, double>, std::allocator<std::pair<unsigned int, double> > > >&, std::pair<unsigned int, double>&)
"/usr/include/c++/4.4/bits/vector.tcc:106: note: candidates are:
__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> > std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = std::pair<unsigned int, double>, _Alloc = std::allocator<std::pair<unsigned int, double> >]
/usr/include/c++/4.4/bits/stl_vector.h:850: note:
void std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&) [with _Tp = std::pair<unsigned int, double>, _Alloc = std::allocator<std::pair<unsigned int, double> >]
어떤 이유가 될 수있다
당신은 (읽을) 응답을 볼 수 있습니까? 그리고 가능한 해결책은 무엇입니까?
iterator insert(iterator, const value_type&);
하지만 당신은 함수에 전달하는 첫 번째 인수는 암시 적으로 변환 할 수없는 const_iterator
입니다 :
그래, 고마워 ... 나는이 코드를 작성하는 동안 매우 피곤한 것 같아 저주를받을 것이다 :) 그건 다소 자동화 된 것이고, 나는 보통 const와'에 대한 인수를 전달하고있다. 그래서 벡터의 간단한'vector :: iterator'로는 반복 될 수 없다. 제 경우에는 로컬 범위에 벡터를 정의 했으므로'const_iterator'를 사용할 필요가 없었습니다. 고맙습니다. –