title: C++ Deck and Card Class Error with bad alloc
body: <p>Just started learn to code in school. Our assignment requires us to create a card game with card,deck and hand class. I am having troubles with it now and i keep getting exception: std::bad_alloc at memory location. Here are my codes right now</p>
  
  <p>CardType h:</p>
  
  <pre><code>#ifndef cardType_h
  #define cardType_h
  #include &lt;string&gt;
  
  using namespace std;
  
  class cardType{
  public:
    void print();
    int getValue() const;
    string getSymbol() const;
    string getSpecial() const;
    string getSuit() const;
    int checkSpecial(int gscore) const;
  
    cardType();
    cardType(string suit,int value);
  
  private:
    int value;
    string special;
    string symbol;
    string suit;
  };
  
  #endif
  </code></pre>
  
  <p>CardType cpp:</p>
  
  <pre><code>#include "cardType.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void cardType::print()
  {
    cout &lt;&lt;  getSymbol() &lt;&lt; " of " &lt;&lt; getSuit() &lt;&lt; ", having the value of " &lt;&lt;           getValue() &lt;&lt; "."&lt;&lt; endl  &lt;&lt;"This card's special is " &lt;&lt; getSpecial() &lt;&lt; endl;
  }
  
  
  int  cardType::getValue() const
  {
    return value;
  }
  
  string cardType::getSymbol() const
  {
    return symbol;
  }
  
  string cardType::getSpecial() const
  {
    return special;
  }
  
  string cardType::getSuit() const
  {
    return suit;
  }
  
  cardType::cardType(){
  
    value=0;      
    symbol="?";       
    special='?';
    suit='?';
  }
  cardType::cardType(string s, int v){
    suit = s;
    value = v;
    switch(v){
      case 1:             // Ace cards have a value of 1  and have no special type
      symbol="Ace";   
      special="None";
      break;
      case 2:             // 2 cards have a value of  2 and have no special type
      symbol="2";
      special="None";
      break;
      case 3:
      symbol="3";     // 3 cards have a value of  3 and have no special type
      special="None";
      break;
      case 4:
      symbol="4";     // 4 cards have a value of  0 and have a special type "Reverse" which reverses the flow of the game
      special="Reverse";
      value=0;
      break;
  case 5:
      symbol="5";     // 5 cards have a value of 5 and have no special type
      special="None";
      break;
  case 6:
      symbol="6";     // 6 cards have a value of  6 and have no special type
      special="None";
      break;
  case 7: 
      symbol="7";     // 7 cards have a value of  7 and have no special type
      special="None";
      break;
  case 8: 
      symbol="8";     // 8 cards have a value of  8 and have no special type
      special="None";
      break;
  case 9: 
      symbol="9";     // 9 cards have a value of  0 and have a special type "Pass" which does not add any value to the game and lets the player skip his turn.
      special="Pass";
      value=0;
      break;
  case 10:
      symbol="10";    // 10 cards have a value of  10 and have a special type "subtract" which instead of adding the 10 value to the total game it is subtracted instead.
      special="Subtract";
      value=10;
      break;
  case 11:            // Jack cards have a value of 10 and have no special type
      symbol="Jack";
      special="None";
      value=10;
      break;
  case 12:            // Queens cards have a value of 10 and have no special type
      symbol="Queen";
      special="None";
      value=10;
      break;
  case 13:    
      symbol="King";  // King cards have a value of 0 and have a special type "NinetyNine" which changes the total game score to 99 reguardless what number it was previously
      special="NinetyNine";
      value=0;
      break;
  }
  
  }
  
  int cardType::checkSpecial(int gscore) const{
  if(special=="Pass"){
      return gscore;
  }
  if(special=="Reverse"){
      return gscore;
  }
  if(special=="Subtract"){
      return gscore - value;
  }
  if(special=="NinetyNine"){
      return 99;
  }
  
  else{
      return gscore + value;
  }
  }
  </code></pre>
  
  <p>DeckType h:</p>
  
  <pre><code>#ifndef deckType_h
  #define deckType_h
  #include "cardType.h"
  #include &lt;string&gt;
  
  using namespace std;
  
  class deckType
  {
  public:
  void shuffle();
  cardType dealCard();
  deckType();
  private: 
  cardType *deck;
  int current;
  };
  
  #endif
  </code></pre>
  
  <p>DeckType cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "deckType.h"
  
  
  using namespace std;
  
  deckType::deckType()
  {   int index = 0;
  int current=0;
  deck = new cardType[52];
  
  string suit[] = {"Hearts","Diamonds","Clubs","Spades"};
  int value[] = {1,2,3,4,5,6,7,8,9,10,11,12,13};
  
    for ( int i = 0; i &lt;= 3; i++ ) {
       for ( int j = 1; j &lt;= 13; j++ ) {
          deck[index] = cardType(suit[i],value[j]);
          index++;
       }
    }
  }
  
  cardType deckType::dealCard()
  {
  return deck[current];
  current++;
  }
  </code></pre>
  
  <p>Main cpp :</p>
  
  <pre><code>#include "deckType.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {   
  deckType gamedeck;
  cout &lt;&lt; "1" &lt;&lt;endl;
  cardType currentCard;
  cout &lt;&lt; "2" &lt;&lt;endl;
  currentCard = gamedeck.dealCard();
  cout &lt;&lt; "3" &lt;&lt;endl;
  
  
  return 0;
  }
  </code></pre>
  
  <p>I keep getting bad_alloc at the currentCard = gamedeck.dealCard();
  I really do not know what i have done wrong.</p>