I am currently implementing classes for labeling support in c++. However, I am a bit confused about the different behaviour of the overloaded operator and isEqual methods:
class Lbl
{
public:
virtual bool operator == (const Lbl* l) const = 0;
virtual bool isEqual (const Lbl* l) const = 0;
};
class SubLbl : public Lbl
{
public:
SubLbl(){}
bool operator == (const Lbl* l) const {return true;}
bool isEqual (const Lbl* l) const {return true;}
};
int main(int argc, char** argv) {
SubLbl* l1 = new SubLbl();
SubLbl* l2 = new SubLbl();
cout << (l1 == l2) << endl;
cout << (l1->isEqual(l2)) << endl;
return 0;
}
Output:
0
1
Why is this? How do I need to change this to get the operator overloaded as well? Why do I have to inherit "public" to have the "isEqual" method be accessable? Or is this just a typical situation for templates which I have not used (and do not know) so far?
What I am doing is implementing different SubLbl classes for the support of different type of labels I can put on objects. All (SubLbl classes) inherit from the Lbl class and should overload the equality operator due to their own equality definitions (int comparison is different to the comparison of two complex objects and even different to a double comparison). Later (in the program) I do not want to know what kind of sub-label I am currently looking at, I just want to know whether they are equal or not.