があります。私はここで私の質問を検索したが、何か関連するものを見つけることに失敗した。 これが問題です。
私はプログラムの中でこのコードを使っています。
私はそれを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'で反復することはできませんでした。私の場合は、ローカルスコープにvectorを定義していましたが、 'const_iterator'を使う必要はありませんでした。ありがとうございました。 –