i've overloaded some comparison operators in my Student class. When i try to use them, the result is uncertain:
class Student {
public:
int ID;
int grade;
int teamID;
int power;
Student(int id,int grade, int power): ID(id),
grade(grade),teamID(-1),power(power){};
~Student() {};
bool operator==(Student* right) {
return this->ID == right->ID;
}
bool operator<(Student* right) {
return this->ID < right->ID;
}
bool operator>(Student* right) {
return this->ID > right->ID;
}
};
And this is where the weird things happen:
for (int i = 0; i < 10; i++) {
Student* s1 = new Student(i + 1, i + 1, i + 1);
Student* s2 = new Student(i + 2, i + 1, i + 1);
cout << (s1 < s2);
}
The result is always some permutation of zeros and ones, nothing stable. I have no idea why this might happen. Can anyone help me? The reason why i'm using pointers is that i use a pointer to Student as a type T for another template class.