我很难弄清楚如何为嵌套枚举类型的类 Card 重载后缀增量运算符。此外,我也很难获得为这门课工作的副本作业。我收到以下错误“运算符 ++ 必须采用一个或零个参数。” 然后,当我尝试提供作业时,我得到
no match for operator= in ((deck*)->this)->Deck::deckArr = operator new
class Card {
public:
enum Suit {
SPADES,
HEARTS,
CLUBS,
DIAMONDS
};
enum Spot {
DEUCE,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE
};
Card();
Card(Card&);
Card(Suit&, Spot&);
~Card();
Suit& operator++(Suit&,int);
Spot& operator++(Spot&,int);
Card& operator=(const Card&);
private:
Spot _spot;
Suit _suit;
};
Card::Suit& Card::operator++(Card::Suit &s, int) {Card::Suit oldsuit = s;
s = (Card::Suit)(s+1);
return oldsuit;}
Card::Spot& Card::operator++(Card::Spot &sp, int){Card::Spot oldspot = sp;
sp = (Card::Spot)(sp+1);
return oldspot;}
Card& Card::operator=(const Card &c){_spot = c._spot; _suit = c._suit; return *this;}
#include "card.h"
class Deck {
public:
Deck();
Deck(Deck&);
~Deck();
void createDeck();
void shuffleDeck(int);
private:
static const int DECK_SIZE = 52;
Card deckArr[DECK_SIZE];
};
void Deck::createDeck(){
int x = 0;
for(Card::Suit s = Card::SPADES; s <= Card::HEARTS; s++){
for(Card::Spot n = Card::DEUCE; n <= Card::ACE; n++, x++){
deckArr[x] = new Card(s, n);
}
}
}