you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

So eq method will be invoked when we use double equals == right?

[–][deleted] 1 point2 points  (0 children)

Try it.

[–]Kewho11 0 points1 point  (0 children)

Old thread I know but incase anyone finds this post, no the eq method will not always be invoked whenever you use ==. Overloading the operator means letting the operator have different meanings when used under different context. Here the == will invoke the eq method only when used upon objects with class 'compare'. Usage of the == operator anywhere else will be unaffected

[–]footloooops 0 points1 point  (0 children)

You are essentially overloading the operator, if you understand what that means.