Skip to content

Instantly share code, notes, and snippets.

@CrBoy
Created August 12, 2012 08:12
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 CrBoy/3330616 to your computer and use it in GitHub Desktop.
Save CrBoy/3330616 to your computer and use it in GitHub Desktop.
Example of using set with custom class
#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