how to sort a deck of cards by rank then suit

i wrote a predicate function to sort the deck by rank , then by suit. in there i have an else expression commented out.

when i comment out the else part , the sort works.

however , when i uncomment the else part , the sort fails.

I am not sure why , i thought the 2 cases would be logically equivalent.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

bool ranksuit(const Card& lhs, const Card& rhs)
{
	bool temp = false;

	if (lhs.rank < rhs.rank)
	{
		if (lhs.suit < rhs.suit)
		{
			return true; 
		}

		/*else ---> commented out to make code work
		{
			return false; 
		}*/

	}
	else {
	
		return false; 
	
	}

	

 
std::pair has relational operators: http://www.cplusplus.com/reference/utility/pair/operators/

The pair has two properties: "first" and "second". They could be "rank" and "suit".

Is your function "logically equivalent" to pair's operator?
temp isnt used.

What I see here is that

if rank is true
if suit is false

... return ??? Nothing provided for this branch!
but this works in VS
there are tons and tons of cool stuff that works just fine and is not technically legal. Void main works in pretty much all compilers and isnt legal, for one example.

Make an explicit result for all branches, then see what happens.
Of the mainstream compilers, void main() 'works' only with the Microsoft compiler;
both the GNU compiler and the LLVM compiler generate a compiler-time error,
even if we don't demand conformance (allow linuxisms). http://coliru.stacked-crooked.com/a/7464f25fdcefdba0
Topic archived. No new replies allowed.