I'm trying to override operator < as the following :
inside Node :
bool operator <(const Node* other) {
return *(this->GetData()) < *(other->GetData());
}
inside vehicle :
bool operator <(const Vehicle &other) {
return this->GetKilometersLeft() < other.GetKilometersLeft();
}
invoking the operator :
while (index > 0 && m_heapVector[index] < m_heapVector[parent(index)])
vector definition :
vector<Node<T>*> m_heapVector;
I c开发者_运维知识库hecked the call and it's not calling the overridden operators.
this is because you are comparing pointers,
You have to make it:
*m_heapVector[index] < *m_heapVector[parent(index)]
and adjust operator accordingly
bool operator<(const Node &other) const;
精彩评论