重载结构体运算符

优先队列重载结构体的运算符常见的方法:

struct Node{
    int x;
    int y;
};

struct cmp{
    bool operator()(Node a,Node b){
        return a.x>b.x;
    }
};

priority_queue<node,vector<node>,cmp> Q;
struct node{
    int x;
    int y;
}point;

bool operator<(const node &a,const node &b)
{
    return a.x>b.x;
}

priority_queue<node> Q;


语法:
<返回类型> operator <运算符符号>(<参数>)
{
    <定义>;
}
struct node{
    int x;
    int y;
    friend bool operator<(const node a,const node b)
    {
        return a.x>b.x;
    }
};

priority_queue<node> Q;
struct node{
    int x;
    int y;
    bool operator<(const node &a) const
    {
        return x>a.x;
    }
};

priority_queue<node> Q;
原文地址:https://www.cnblogs.com/shiliuxinya/p/12196212.html