Suppose I have a type hierarchy:
struct B { ... }; struct D1 : B { ... }; struct D2 : B { ... }; ... struct Dn : B { ... };
Each Di has its own operator== defined:
struct Di : B { bool operator==(const Di&) const { ... } ... };
Now I want to define B operator== so that:
struct B { bool operator==(const B& that) const { // psuedo-code let i, such the dynamic type of this is Di let j, such the dynamic type of that is Dj if (i != j) return false; else return Di::operator==(this, that); } }
What is the best way to organize this or write it?
(The ultimate goal is that I want to use standard container types with a value of type B * (for example, std::set<B*> ), but to do this use custom Di::operator==s if they belong to the same the same derived class)
c ++ c ++ 11
Andrew Tomazos
source share