C++ – Overloaded operators

struct nodef {
    string name;
    int score;
    bool operator <(const nodef &n) const {
        return this -> score < n.score;
    }
};

These sentences indicate that a structure named nodef has been established. Its member variables include name and score. The operator < is overloaded, which means that when a nodef and nodef are used for the < operation, the second nodef is passed in as the parameter n. And the return value of the operation is bool type, and the comparison is based on the score variable.

Post Reply