Cards.h
class Card
{
public:
// Card suits
struct Suit
{
// Suits in order
enum Enum
{
Clubs,
Diamonds,
Hearts,
Spades,
};
};
// Card rank
struct Rank
{
// Ranks with aces low
enum Enum
{
Ace,
Two,
King,
....
...
};
};
// constructors
//get & set functions
//predicate
friend bool compareCardsSuit(const Card & cardlhs, const Card & cardrhs)
{
return cardlhs.GetSuit() == cardrhs.GetSuit();
}
friend bool operator==(Card const& lhs, Card const& rhs) // THis func is used for some other purpose
{
// We only care about rank during equality
return lhs.m_rank == rhs.m_rank;
}
hands.h
class Hand
{
public:
static int const Size = 5;
// The type of hand we have
struct Type
{
// Type of hand in accending order
enum Enum
{
HighCard,// Five cards which do not form any of the combinations below
Flush, // Five cards of the same suit
bla,
bla..
};
};
// Object creation
// other functiosn
private:
mutable std::array<Card, Size> m_cards;
Type::Enum m_type;
// Hand calculations
Type::Enum Evaluate();
hands.cpp
Hand::Type::Enum Hand::Evaluate()
{
std::equal(m_cards.begin(), m_cards.end(), compareCardsSuit); // got error
{
return Hand::Type::Flush;
}
// Return our hand
return Hand::Type::HighCard;
}
All I want is to check that if member data of m_cards has identical suit then return flush..
I am getting error as shwon below
Error 3 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Card' (or there is no acceptable conversion)
Error 2 error C2171: '++' : illegal on operands of type 'bool (__cdecl *)(const Card &,const Card &)'
To check for a specific suit you could use
std::all_of
To check all adjacent cards are verifying some criteria you could use
std::adjacent_find
or simply
Last one will use
operator==(const Card&, const Card&)
as a predicateP.S. Code above is written by heart in the default SO text editor and has never been compiled. Sorry for possible typos.