1
我正在尝试使用模板参数std::less
,std::greater
或。这是后续到this question,因为答案没有提供完整的示例,我无法成功使用模板比较器。使用模板比较器的完整示例
#include <functional>
#include <algorithm>
template <typename C>
class Test
{
int compare(int l, int n, int x, int y)
{
public:
bool z = C(x, y);
if(l < n && z)
{
return 1;
}
else
{
return 2;
}
}
};
int main() {
Test<std::less<int>> foo;
Test<std::greater<int>> bar;
foo.compare(1, 2, 3, 4);
bar.compare(1, 2, 3, 4);
}
变化'布尔Z = C(X,Y);'到'布尔Z = C {}(X, Y);'。 – ildjarn
“我无法工作”是什么意思? – user4759923