Created
October 20, 2016 01:35
-
-
Save buyoh/aa61d45b56203c39eb9a62be35243b0f to your computer and use it in GitHub Desktop.
C++に限らずoperator<の比較演算子実装って混乱しませんか?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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