Namara

毎日コード。手助けなし。

2026-08-20

point.cpp

struct Point {
    int x;
    int y;

    // write operator== here
};

2つのPointxyがどちらも等しいときに等しいと判定されるよう、operator==を実装してください。

参考実装
bool operator==(const Point& a, const Point& b) {
    return a.x == b.x && a.y == b.y;
}

ここではフリー関数として書いていますが、メンバ関数としてbool operator==(const Point& other) constを定義し、x == other.x && y == other.yを比較する形でも同じように機能します。