C++ 类中什么时候需要一个operator<

简介

当涉及类对象的排序的时候可以直接构建一个符号重定义函数
比如以set来组织对象的时候,对象最好带一个operator<函数

code

    /* used to use Vertex as key in a map */
    bool operator<(const Vertex&v) const {
        if(x < v.X()) return true;
        else if (x > v.X()) return false;
        else if (y < v.Y()) return true;
        else if (y > v.Y()) return false;
        else if (z < v.Z()) return true;
        else if (z > v.Z()) return false;
        return false; 
    }
原文地址:https://www.cnblogs.com/eat-too-much/p/14327161.html