How to use the comparison operator(<) in user-defined Priority Queue?

Hi.. I am new to C++,I want to create a Priority Queue class, I don't know How to use the comparison operator( operator < method ) in my class and why we are using that?

for example if I defined (operator <) method
bool operator <(MyClass &A,MyClass &B){return (A.getValue()<B.getValue)}

so now how can I use the "<" in my class? I am really confused with this (operator <) because it's just return the true or false.

Last edited on
It returns true if A is less than B, false otherwise.

1
2
MyClass A, B;
A < B; //That's how. 


Why you're to be using that and in what context is anyone's guess, though, I'm afraid. :)

-Albatross
Last edited on
BTW, your operator should take const arguments:

bool operator < ( const MyClass& A, const MyClass& B ) ...
Topic archived. No new replies allowed.