Hi, I am having trouble compiling a simple piece of code. I am creating a class that implements a deck of cards, and I want to create a shuffle method using the list :: short method.
Relevant Code:
deck.h
#ifndef _DECK_H #define _DECK_H #include <list> #include <ostream> #include "Card.h" #include "RandomGenerator.h" using namespace std; class Deck { private: static const int CARD_NUMBER = Card::CARDS_PER_SUIT*Card::SUIT_NUMBER; list<Card *> *cards; RandomGenerator rg; public: Deck(); ~Deck(); void shuffle(); private: bool const compareRandom(const Card *a, const Card *b); }; #endif /* _DECK_H */
deck.cc:
#include "Deck.h" Deck::Deck() { cards = new list<Card *>(); for(int i = 0; i < CARD_NUMBER; i++) cards->push_back( new Card( Card::Suit(int(i/Card::CARDS_PER_SUIT)), i%Card::CARDS_PER_SUIT) ); } Deck::~Deck() { gather(); for(list<Card *>::iterator c = cards->begin(); c != cards->end(); c++) delete *c; delete cards; } bool const Deck::compareRandom(const Card *a, const Card *b) { return rg.randomBool(); } void Deck::shuffle() { cards->sort(compareRandom); }
The compiler displays the following message (ignores line numbers):
Deck.cc: In member function 'void Deck::shuffle()': Deck.cc:66: error: no matching function for call to 'std::list<Card*, std::allocator<Card*> >::sort(<unresolved overloaded function type>)' /usr/include/c++/4.3/bits/list.tcc:303: note: candidates are: void std::list<_Tp, _Alloc>::sort() [with _Tp = Card*, _Alloc = std::allocator<Card*>] /usr/include/c++/4.3/bits/list.tcc:380: note: void std::list<_Tp, _Alloc>::sort(_StrictWeakOrdering) [with _StrictWeakOrdering = const bool (Deck::*)(const Card*, const Card*), _Tp = Card*, _Alloc = std::allocator<Card*>]
The problem should be on the compareRandom link, which I am using incorrectly, I can not find the answer to this problem.
Thanks in advance.
source share