无法将std :: lower_bound返回值分配给vector :: iterater

时间:2019-01-31 03:59:31

标签: c++ vector types const

传递给函数:const std :: vector&xv:

std::vector<float>::iterator lowBound = lower_bound(xv.begin(), xv.end(), x);

在将std::vector<float>&更改为const std::vector<float>&之前,该功能运行良好

Lower_bound在编译时返回语法错误,提示:

no suitable user-defined conversion from "__gnu_cxx::__normal_iterator<const float *, std::vector<float, std::allocator<float>>>" to "__gnu_cxx::__normal_iterator<float *, std::vector<float, std::allocator<float>>>" exists
std::vector<...>::const_iterator std::lower_bound<std::vector<float, std::allocator<float>>::const_iterator, float>(std::vector<...>::const_iterator __first, std::vector<...>::const_iterator __last, const float &__val)

我尝试将std::vector<float>::iterator更改为const std::vector<float>::iterator,也尝试了std::vector<const float>::iterator

这些选项似乎都不起作用。

很抱歉给我带来麻烦,我尝试搜索该错误并且无法给出答案。

2 个答案:

答案 0 :(得分:0)

lower_bound返回一个const_iterator。您需要

std::vector<float>::const_iterator lowBound = lower_bound(xv.begin(), xv.end(), x);

或者只是(C ++ 11)

auto lowBound = lower_bound(xv.begin(), xv.end(), x);

Demo

答案 1 :(得分:0)

显然我应该使用:

update legheader set lgh_extrainfo1 = ( Select Case When L.lgh_split_flag <> 'N' and L.lgh_carrier = 'UNKNOWN' Then Case When TR.trc_type1 = 'O/O' and TR.trc_type3 = '70Per' Then CAST (.7 * ((Cast (L.lgh_miles as decimal (10,2))/O.ord_totalmiles) * L.lgh_ord_charge)as decimal (10,2)) When TR.trc_type1 = 'O/O' and TR.trc_type3 <> '70Per' Then CAST (.64 * ((Cast (L.lgh_miles as decimal (10,2))/O.ord_totalmiles) * L.lgh_ord_charge)as decimal (10,2)) END When L.lgh_split_flag = 'N' and L.lgh_carrier = 'UNKNOWN' Then Case When TR.trc_type1 = 'O/O' and TR.trc_type3 = '70Per' Then CAST (.7 * L.lgh_ord_charge as decimal (10,2)) When TR.trc_type1 = 'O/O' and TR.trc_type3 <> '70Per' Then CAST (.64 * L.lgh_ord_charge as decimal (10,2)) END End From Legheader L Left Join TractorProfile TR on L.lgh_tractor = TR.trc_number Left Join Orderheader O on O.ord_hdrnumber = L.ord_hdrnumber) 而不是const std::vector<float>::const_iterator

不知道有单独的数据类型。

所以答案是:std::vector<float>::iterator