gpt4 book ai didi

c++ - 如何使用 std::rel_ops 自动提供比较运算符?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:21:56 25 4
gpt4 key购买 nike

<分区>

如何获取运算符 > , >= , <= , 和 !=来自 ==<

标准标题 <utility>定义一个命名空间 std::rel_ops,它根据运算符 == 定义上述运算符和 < ,但我不知道如何使用它(哄骗我的代码将此类定义用于:

std::sort(v.begin(), v.end(), std::greater<MyType>); 

我在其中定义了非成员运算符:

bool operator < (const MyType & lhs, const MyType & rhs);
bool operator == (const MyType & lhs, const MyType & rhs);

如果我#include <utility>并指定 using namespace std::rel_ops;编译器仍然提示 binary '>' : no operator found which takes a left-hand operand of type 'MyType' ..

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com