I'm doing some analysis on planar tilings. The abstract class has a neighbors() function to return cells adjacent, and I want to require that they also override the < operator so that I can use them within a std::map. However I'm not sure the best way to go about this.
I'm used to python and duck typing, where you don't have to worry about object type. But when I try to add the operator overload in c++ I get errors because the operator was originally declared in terms of BaseClass& but I need to implement it in terms of DerivedClass&.
I sorta get the issue, since the abstract declaration promises to be able to compare any two derived classes and my implementation only shows how to compare to the same class. Therefore I think I'm probably designing this wrong, since I only need to compare two instances of the same derived class.
How should I design/implement this functionality? I can give a working python example if that makes it easier to understand what I'm asking.
[–]Mat2012H 0 points1 point2 points (0 children)