title: c++ confusing state variable behaviour
body: <p>I have a class "CardT" the contains a suit and number stored by an enum value. For the use of solitaire i create a deck of 52 of these cards with each value. I also have a "tableau" class that stores a set of these cards for the solitaire tableau, my board class contains an array of 8 of these. After placing the values in the array and printing to check for correctness, it gives a correct output. But if i then call another function right after that prints the exact same thing, i get very different values.</p>
  
  <pre><code>int main(){
      Board b;
      b.setUp();  //setUp deck and add to tableau arrays
      b.printTab(4); //print the fourth one again
  }
  </code></pre>
  
  <p>Where deck gets setup</p>
  
  <pre><code>void Board::setUp(){
  //here i setup all 52
  CardT deck[52];
  int c = 0;
  for (int i = 0; i &lt;= 3; i++)
      for (int j = 1; j &lt;=13;j++){
          deck[c] = CardT(static_cast&lt;CardSuit&gt;(i),static_cast&lt;CardNum&gt;(j));
          c++;
      }
  //shuffle
  std::random_shuffle(&amp;deck[0],&amp;deck[52]);
  
  CardT tabls[8][13]; 
  for (int i = 0; i &lt; 4; i++)
      for (int j = 0; j &lt; 8; j++)
          tabls[i][j] = deck[j + i*8];  //the first 4 piles that contain 8 cards
  
  for (int i = 4; i &lt; 8; i++)
      for (int j = 0; j &lt; 7;j++)
          tabls[i][j] = deck[j + i*8]; //last four with seven
  
  for (int i = 0; i &lt; 4; i++)
      this-&gt;tableauPiles[i] = TableauPileT(tabls[i],8); //place first four, (second param is size)
  
  for (int i = 4; i &lt; 8; i++)
      this-&gt;tableauPiles[i] = TableauPileT(tabls[i],7); //place second four
  
  for (int i = 0; i &lt; 4;i++)
      this-&gt;foundationPiles[i] = FoundationPileT(); //just intialize
  
  
  //FOR testing
  for (int j = 0; j &lt; 13; j++){
      if (this-&gt;tableauPiles[4].cardAtIndex(j)){
          std::cout &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getNum() &lt;&lt; ",,,," &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getSuit() &lt;&lt; std::endl;
  
      }
  }
  //printed twice for assurance, both print as expected
  for (int j = 0; j &lt; 13; j++){
      if (this-&gt;tableauPiles[4].cardAtIndex(j)){
          std::cout &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getNum() &lt;&lt; ",,-,," &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getSuit() &lt;&lt; std::endl;
  
      }
  }
  
  
  }
  </code></pre>
  
  <p>Heres where i then print the exact same thing again:</p>
  
  <pre><code>void Board::printTab(int i){
      for (int j = 0; j &lt; 13; j++){
          if (this-&gt;tableauPiles[4].cardAtIndex(j)){
              std::cout &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getNum() &lt;&lt; ",,Third,," &lt;&lt; this-&gt;tableauPiles[4].getCardByIndex(j).getSuit() &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The header for the board</p>
  
  <pre><code>#ifndef BOARD_H
  #define BOARD_H
  
  class Board{
  private:
  
  CardT freeCells[4];
  bool freeCellsOpen[4] = {false,false,false,false};
  FoundationPileT foundationPiles[4];
  TableauPileT tableauPiles[8];
  
  int cardPosition(CardNum n, CardSuit s);
  int emptyFreeCell();
  
  public:
  
  Board();
  void setUp();
  void moveToFreeCell(CardNum n, CardSuit s);
  void moveToTableau(CardNum n, CardSuit s, int tableau);
  void moveToFoundation(CardNum n, CardSuit s);
  void printBoard();
  void printTab(int i);
  };
  
  
  #endif
  </code></pre>
  
  <p>And finally this is then the output im given </p>
  
  <pre><code>1,,,,1
  12,,,,2
  4,,,,0
  4,,,,1
  4,,,,2
  5,,,,3
  10,,,,0
  1,,-,,1
  12,,-,,2
  4,,-,,0
  4,,-,,1
  4,,-,,2
  5,,-,,3
  10,,-,,0
  1,,Third,,1
  0,,Third,,1
  0,,Third,,0
  32545,,Third,,1284192187
  0,,Third,,10
  32767,,Third,,1922833024
  0,,Third,,0
  </code></pre>
  
  <p>The printed values are stored as enum.</p>
  
  <p>Clearly changed between print statements, very new to c++ but have c experience among others. Any help is greatly appreciated as im going out of my mind.</p>
  
  <p>Also im printing the 4th pile, i believe the 0-3 pile all print correctly, just 4+ are getting messed.</p>
  
  <p>Also of note, the large unexpected values are changing between executions, rest stay constant.</p>