This works for when I'm comparing objects of a class:
//first number is row, then column, then a value which doesnt get compared.
Element e1 (4, 2, 4);
Element e2 (5, 2, 4);
if (e1 > e2)
cout << "e1 is greater than e2" << endl;
else
cout << "e1 is not greater than e2" << endl;
bool Element::operator > (const Element& e) const
{
return ((this -> row == e.row) && (this -> col > e.col)) || (this -> row > e.row);
}
... but not when I compare it after I have them in a linked list node.
if (curr -> e > head -> e /*<---- STOPS WORKING HERE*/ || curr -> e == head -> e /* <---- THIS == OPERATOR WORKS HOWEVER*/)
{
cout << "inserted befrore not empty head" << endl;
newNode -> next = head;
head = newNode;
}
The program stops running when I try comparing curr -> e
to head -> e
. I'm not sure why but I have another operator overload function that checks if the two nodes are equal, and that seems to be working when compared using nodes. Here it is just for reference.
bool Element::operator == (const Element& e) const
{
return ((this -> row == e.row) &&
(this -> col == e.col));
}
The >
operator overload function gives me a runtime error when comparing two nodes. Solutions?