<分区>
我有一个类提供可由 std::sort
使用的自定义静态比较器。以下将编译得很好(精简为最小代码示例):
#include <vector>
#include <string>
#include <algorithm>
class StringUtils
{
public:
static bool customStringCompare(const std::string&, const std::string&) { return true; }
};
void test()
{
std::vector<std::string> testList;
std::sort(testList.begin(), testList.end(), StringUtils::customStringCompare);
}
现在,当我向 StringUtils 类添加重载时,例如
static bool customStringCompare(const char*, const char*) { return true; }
以下将起作用:
void test2()
{
std::string s1, s2;
StringUtils::customStringCompare(s1, s2);
}
但是,上面的 std::sort
调用会产生编译器错误 C2672(未找到匹配的重载)、C2780(预期 2 个参数 - 支持 3 个)、C2783(“_Pr”的模板参数无法找到推导)在 MSVC 2015 更新 2.
为什么 std::sort
在这种情况下找不到匹配的重载?