使用upper_bound比较器时出错



当我运行"upper_ bound";使用比较器,它会给我以下错误:error:引用类型'conststd::vector<int,std::分配器>'无法绑定到"const int"类型的左值。有人知道这个问题吗?

static bool compareInterval(const vector<int>& a, const vector<int>& b) {
return (a[0] < b[0]);
}
vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n) {
vector<int> ret(n, 0);
sort(bookings.begin(), bookings.end(), compareInterval);

for (int i = 0; i < n; ++i) {
auto low=upper_bound(bookings.begin(), bookings.end(), i, compareInterval);
}
return ret;
}

包含在prog_joind.cpp:1:包含在文件中./precompiled/headers.h:13:包含在的文件中/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//包括/c++/9/c日期:1927:在包含的文件中/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//include/c++/9/bits/specfun.h:45:在包含的文件中/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//include/c++/9/bitss/sstl_algobase.h:71:/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//include/c++/9/bits/predefined_ops。h:21:24:错误:引用类型'conststd::vector<int,std::分配器>'无法绑定到"const int"类型的左值{return bool(_M_comp(__val,__it((;}^~~~~/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//包括/c++/9/bits/sstl_alg.h:2051:8:注意:在函数模板专业化的实例化中'__gnu_cxx::__ops::_Val_comp_iter<bool(((const-std::vector<int,std::分配器>amp;,conststd::vector<int,std::分配器>&(>:运算符((<const int,__gnucxx::__normal_iterator<std::vector<int,std::分配器>*,std::vector<std::vector<int,std::分配器>,std::分配器<std::vector<int,std::分配器>gt>gt>'请求在这里if(__comp(__val,__middle((^/usr/bin//lib/gcc/x86_64-linux-gnu/9/../..//包括/c++/9/bits/sstl_alg.h:2116:19:注意:在函数模板专业化的实例化中'std::__upper_bound&lt__gnucxx::__normal_iterator<std::vector<int,std::分配器>,std::vector<std::vector<int,std::分配器>,std::分配器<std::vector<int,std::分配器>gt>gt;,int,__gnu_cxx::__ops:_Val_comp_iter<bool(((const std::vector<int,std::分配器>&,conststd::vector<int,std::分配器>amp;(>gt;'此处请求return std::__upper_bound(__first,__last,__val,^第12行:字符22:注意:在函数模板专业化的实例化中'std::upper_bound&lt__gnucxx::__normal_iterator<std::vector<int,std::分配器>,std::vector<std::vector<int,std::分配器>,std::分配器<std::vector<int,std::分配器>gt>gt;,int、bool(((conststd::vector<int,std::分配器>amp;,conststd::vector<int,std::分配器>&(>'此处请求auto-low=upper_bound(bookings.begin((,bookings.end((,i,compareInterval(;^生成1个错误。

事实证明"i〃;需要包装成与预订元素相同的类型

最新更新