【发布时间】:2011-04-20 20:39:30
【问题描述】:
那里。我在这里搜索了我的问题,但没有找到任何相关的内容。
这就是问题所在。
我在程序的一部分中有这段代码,通过插入进行了一种愚蠢的排序。
我在 MSVS 2008 中开发了它,一切正常,但是当我尝试用 g++ 编译它时,由于下面的 list::insert 函数而失败;
//...
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 的类型为pair,其内容类型与NewList 的内容类型相同;
在那里你可以看到响应(不可读):
main.cpp:447: 错误:没有匹配函数调用“
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:注意:候选人是:
__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:注意:
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> >]
可能是什么原因?什么是可能的解决方案?
【问题讨论】:
标签: c++ list stl g++ compiler-errors