小编Joh*_*ins的帖子

有没有更好的方法在 C++ 20 之前的 C++ 中定义关系运算符?

写代码对我来说很乏味

class date {
private: 
    int day, year, month;
    int comp(const date & Other) const;
public:
    date(int D, int Y, int M) : day (D), year (Y), month (M)  {}

    friend bool operator==(const date & L, const date & R) { return L.comp(R) == 0 ; }
    friend bool operator!=(const date & L, const date & R) { return L.comp(R) != 0 ; }
    friend bool operator> (const date & L, const date & R) { return L.comp(R) > 0 …
Run Code Online (Sandbox Code Playgroud)

c++ operators comparison-operators c++17

3
推荐指数
1
解决办法
155
查看次数

标签 统计

c++ ×1

c++17 ×1

comparison-operators ×1

operators ×1