Reputation: 949
In my class, I write the prototype (public) as:
bool operator< (const MyClass& obj);
I implement the method outside the class (in the same file) as:
bool MyClass::operator< (const MyClass& obj)
{
cout << "operator< used" << endl;
//do my work
}
The problem is that although my overloading operator gets called if I call it explicitly (like obj1->operator<(*obj2)
) but not when called implicitly (like obj1 < obj2
).
I have followed overloading tutorial from this article and I can't see what I'm missing or doing wrong.
Upvotes: 2
Views: 127
Reputation: 361
obj1 and obj2 are pointers to MyClass. if you want to call operator < use: *obj1 < *obj2
Upvotes: 1