这个
比较函数
你提供的不是
functor
.
应该是
using Pair = std::pair<const std::string, float>; // just a alias type for convenience
struct Tool
{
bool operator()(const Pair& i, const Pair& j)const
/*^^^^^^^^*/ /*^^^*/
{
return (i.second < j.second);
}
};
你应该这样称呼它
min = *min_element(direction.begin(), direction.end(), Tool());
^^^^^^
但是,如果您可以访问C++ 11或更高版本,只需使用lambda,这将帮助您在调用的行上看到比较函数(二进制谓词)的定义。
min = *min_element(direction.begin(), direction.end(),
[](const auto& lhs, const auto& rhs){ return lhs.second < rhs.second;});