Hi all,
I could have sworn the c++ faq had the answer for this question but I
can't seem to find it, so here goes:
Suppose you have a single-rooted class hierarchy. Call the root class
Object. How can we provide operator overloading for the whole
hierarchy? e.g. provide == for the whole hierarchy?
Even more specifically: suppose we define
bool operator==(const Object* lhs, const Object* rhs) {
return lhs == rhs;
}
but we want to allow subclasses to override this behaviour by
overrididing some (virtual) method(s), so that even if you have only a
pointer to the base class (e.g. Object) the right comparison is made.
What is the best way to organize things?
TIA, best regards,
G. Rodrigues