Hello,
I have a virtual class Element that forces its derived classes to have a == operator:
class Element {
virtual int operator==(Element *)=0;
}
So, I have derived classes (Integer, Word) that implement that operator.
I have a class Group that basically is a list of elements.
In a function, I want to compare if an element from a group its equal to an element of a different group, so I'm using:
if(actual == lookingfor)
where both actual and lookingfor are pointers to Element...but the comparison is being made at the level of pointers, so both pointers are always different.
How can I force that the operator == from the derived class of element be used?
> the base function for comparison uses pointer to element,
> I have to stick to this declaration:
Hmm.. that looks counter-intuitive to me; if it is your own base class, consider modifying it. And while you are at it, also make the code const-correct.