Yet another issue I'm having when over riding operators. At the moment I'm trying to figure out why when I over ride the "<" operator it consitantly gives false comparisons for certain pieces of input. I currently have an enum type called Rank as shown.
enum Rank
{
TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE
};
These are given the value 0-12 respectively. In the implentation class I am just trying to do this:
bool operator<(Card &lhs, Card &rhs)
{
return lhs.getRank() < rhs.getRank();
}
For the most part it works, however every time I run the program it gives me a warning that says:
"warning: comparison between signed and unsigned integer expressions [-Wsign-compare]"
It will then evaluate most of the comparison correctly, however it will always place the KING and the ACE ranks between EIGHT and SEVEN when ordering the ranks from strongest to weakest. Here is some sample results with their rankings next to them.
1.) Queen(10), Jack(9), King(11), Six(4), Seven(5)
2.) Ten(8), Eight(6), Ace(12), Six(4), Two(0)
3.) Queen(10), Nine(7), Ace(12), King(11), Seven(5)
When I compare the ranks without using the over ridden comparison, but rather by doing it the normal way all the cards will compare as they should and go into order. I've been scratching my head at this for a few hours so if you guys know what's up that'd be great.
I can post my code if you feel like reading it, but I don't think the cause of the problem is in something I haven't shown.