重载运算符

重载小于号错误的写法

sturct node{
     int id,dis;
     bool operator<(node x)const{
          return x.dis<dis;                    
     }
}

正确的写法

sturct node{
     int id,dis;
     bool operator<(node x)const{
          return dis<x.dis;                    
     }
}

易于区分的写法 :friend 友元

struct node{
     int id,dis;
     friend bool operator<(node x,node y){
         return x.dis<y.dis;
     }
};
posted @ 2022-05-13 09:31  Chano_sb  阅读(38)  评论(0)    收藏  举报