我正在研究一个C++程序,其中指向class(航空类)的指针是排序向量中的对象.我想确定航空公司是否已经是向量中的指向对象.首先我使用lambda应用lower_bound,它是成功的.然后我用相同的lambda实现binary_search,但它失败了.错误信息如下,
Run Code Online (Sandbox Code Playgroud)__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { __first = __lower_bound<_Compare>(__first, __last, __value_, __comp); return __first != __last && !__comp(__value_, *__first); } /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:4139:13: No matching function for call to object of type '(lambda at /Users/.../Desktop/Programming/C++/trial/trial/main.cpp:188:61)'
它看起来lambda在二进制搜索中不起作用.你能帮我搞清楚它为什么没有?非常感谢!
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class vector_test{
public:
vector_test(string name_) : name(name_) {}
const string get_name() const {return name;}
private:
string name;
};
typedef vector<vector_test*> vector_container;
int main()
{
vector_container test;
string name = "Delta"; …Run Code Online (Sandbox Code Playgroud)