Created
August 12, 2012 08:12
-
-
Save CrBoy/3330616 to your computer and use it in GitHub Desktop.
Example of using set with custom class
This file contains hidden or 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> | |
#include <set> | |
using namespace std; | |
class MyClass{ | |
public: | |
MyClass (int _x, int _y):x(_x),y(_y){} | |
bool operator<(const MyClass& rhs) const { | |
return this->x < rhs.x ? true : (this->y < rhs.y ? true : false); | |
} | |
private: | |
int x; | |
int y; | |
}; | |
int main(int argc, const char *argv[]) | |
{ | |
set<int> s1; | |
set<MyClass> s2; | |
for(int i = 0; i < 10; i++){ | |
s1.insert(i); | |
s2.insert(MyClass(i,10)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment