我正在尝试为二维向量上的二进制搜索程序编写代码。我试过代码。但我不明白我有什么错误。我在下面给出了我的代码和错误。
class BINARY_ON
{
public:
explicit BINARY_ON(int column,string fCol) :m_column(column),fColType(fCol) {}
bool operator()(const string& lhs,const vector<string>& rhs)
{
if(fColType=="number")
return atoi(lhs.c_str()) < atoi(rhs[m_column].c_str());
else if(fColType=="date")
return PPCheckTwoDate(lhs, rhs[m_column])<0;
else
return lhs < rhs[m_column];
}
private:
int m_column;
string fColType;
};
int main ()
{
vector<vector<string>> table_data;
// Vector Data Insert
BINARY_ON compare_column(4,"date");
if (std::binary_search (table_data.begin(), table_data.end(), "01051996", compare_column))
std::cout << "found!\n"; else std::cout << "not found.\n";
}
我收到以下错误。
> /usr/include/c++/4.6/bits/stl_algo.h:2416:4: error: no match for call
> to ‘(PPBINARY_ON) (std::vector<std::basic_string<char> >&, const char
> [9])’
>
> note: bool PPBINARY_ON::operator()(const string&, const
> std::vector<std::basic_string<char> >&)
>
> note: no known conversion for
> argument 1 from ‘std::vector<std::basic_string<char> >’ to ‘const
> string& {aka const std::basic_string<char>&}’