dimanche 25 mars 2018

Integrate a polymorphic extendable sorting order

Suppose I have a base class B, and two derived classes C, D.

If I put objects of C and D in a vector, I can sort the vector by type by overloading the lessThan operator to take two objects of type B and do the necessary comparisons in there. For instance I can give each class a sorting ID and compare that to determine, if C comes before D or vice versa. Let's assume now the sorting order is C

Hence, how would I implement such an extendable sorting order, without needing to change C and D, when I add a new class E?

Aucun commentaire:

Enregistrer un commentaire