Note that there are some explanatory texts on larger screens.

plurals
  1. POPostfix incrementer overloading for nested enumerated types
    text
    copied!<p>I am having difficulty figuring out how to overload the postfix increment operator for an nested enumerated type of class Card. Moreover, I am also having difficulty getting copy assignment to work for this class. I am getting the following errors "operator++ must take one or zero arguments." Then, when I attempt to provide assignment I get </p> <pre><code>no match for operator= in ((deck*)-&gt;this)-&gt;Deck::deckArr = operator new </code></pre> <hr> <pre><code>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&amp;); Card(Suit&amp;, Spot&amp;); ~Card(); Suit&amp; operator++(Suit&amp;,int); Spot&amp; operator++(Spot&amp;,int); Card&amp; operator=(const Card&amp;); private: Spot _spot; Suit _suit; }; Card::Suit&amp; Card::operator++(Card::Suit &amp;s, int) {Card::Suit oldsuit = s; s = (Card::Suit)(s+1); return oldsuit;} Card::Spot&amp; Card::operator++(Card::Spot &amp;sp, int){Card::Spot oldspot = sp; sp = (Card::Spot)(sp+1); return oldspot;} Card&amp; Card::operator=(const Card &amp;c){_spot = c._spot; _suit = c._suit; return *this;} #include "card.h" class Deck { public: Deck(); Deck(Deck&amp;); ~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 &lt;= Card::HEARTS; s++){ for(Card::Spot n = Card::DEUCE; n &lt;= Card::ACE; n++, x++){ deckArr[x] = new Card(s, n); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload