bool operator()(const string *ps1, const string *ps2) const
{
return !( *ps1 < *ps2); // just negate the old test;
} // this is incorrect!
};
想法是通过将比较函数内部结果取反来反序。很不幸,取反“<”不会给你(你所期望的)“>”,它给你的是“>=”。而你现在知道,因为“>=”将对相同的元素返回true,对关联容器,它不是一个有效的比较函数。
你真正需要的比较类型是这个:
struct stringptrgreater: // this is a valid
public binary_function<const string*, // comparison type for