Skip to content

Instantly share code, notes, and snippets.

@buyoh
Created October 20, 2016 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buyoh/aa61d45b56203c39eb9a62be35243b0f to your computer and use it in GitHub Desktop.
Save buyoh/aa61d45b56203c39eb9a62be35243b0f to your computer and use it in GitHub Desktop.
C++に限らずoperator<の比較演算子実装って混乱しませんか?
#include<iostream>
using namespace std;
struct S{
int val;
bool operator<(const S& s)const{
return val<s.val;
}
};
bool operator>(const S& l,const S& r){
return l.val>r.val;
}
int m,n;
int main(){
S s1,s2;
s1.val=3;
s2.val=5;
cout << (s1 < s2) << endl;
cout << (s2 > s1) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment