title: Problems with implementing a simple deck of cards. Undefined reference to Class::Constructor, Class::Destructor
body: <p>Hey guys I'm trying to implement a deck of cards in C++. and it's starting to drive me mad.</p>
  
  <p>Please could you have a look at my code and point out any of the mistakes and how to change them?</p>
  
  <p>ATM I'm getting:</p>
  
  <p>in test.cpp undefined reference to Deck::~Deck()</p>
  
  <p>in deck.cpp undefined reference to Card::Card()</p>
  
  <p>in deck.cpp undefined reference to Card::~Card()</p>
  
  <p>Card.h</p>
  
  <pre><code>#ifndef CARD_H
  #define CARD_H
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  enum cardRank { c2, c3, c4, c5, c6, c7, c8, c9, c10, J, Q, K, A };
  enum cardSuit { S, H, D, C };
  
  class Card{
  private:
      int rank;
      int suit;
  public:
      Card();
      Card(int r, int s);
      ~Card();
  
      int getRank();
  
      int getSuit();
  
      void printCard();
  
  };
  
  
  #endif
  </code></pre>
  
  <p>Card.cpp</p>
  
  <pre><code>#include "Card.h"
  
      Card::Card(int r, int s): rank(r), suit(s) {}
  
      int Card::getRank(){
          return rank;
      }
  
      int Card::getSuit() {
          return suit;
      }
  
      void Card::printCard() {
          string r;
          string s;
          switch(rank) {
              case 0:
                  r = '2';
                  break;
              case 1:
                  r = '3';
                  break;
              case 2:
                  r = '4';
                  break;
              case 3:
                  r = '5';
                  break;
              case 4:
                  r = '6';
                  break;
              case 5:
                  r = '7';
                  break;
              case 6:
                  r = '8';
                  break;
              case 7:
                  r = '9';
                  break;
              case 8:
                  r = "10";
                  break;
              case 9:
                  r = 'J';
                  break;
              case 10:
                  r = 'Q';
                  break;
              case 11:
                  r = 'K';
                  break;
              case 12:
                  r = 'A';
                  break;
          }
          switch(suit) {
              case 0:
                  s = 'S';
                  break;
              case 1:
                  s = 'H';
                  break;
              case 2:
                  s = 'D';
                  break;
              case 3:
                  s = 'C';
                  break;
          }
          cout &lt;&lt; '(' &lt;&lt; r &lt;&lt; ", " &lt;&lt; s &lt;&lt; ")";
      }
  </code></pre>
  
  <p>Deck.h</p>
  
  <pre><code>#ifndef DECK_H
  #define DECK_H
  #include "Card.h"
  #include "random/randomc.h"
  #include &lt;time.h&gt;
  
  
  using namespace std;
  
  class Deck{
  private:
      CRandomMersenne random;
      Card deck[51];
      bool dealt[51];
  public:
      Deck();
      ~Deck();
  
      Card * deal();
  
  };
  
  #endif
  </code></pre>
  
  <p>Deck.cpp</p>
  
  <pre><code>#include "Deck.h"
  
      Deck::Deck() : random((int)time(0)){
          for (int i = 0; i &lt; 52; i ++) {
              deck[i] = Card(i % 13, i % 4 );
              dealt[i] = false;
          }
      }
      /*
      Deck::~Deck() {
          for (int i = 0; i &lt; 52; i++) {
              delete deck[i];
          }
      }
  */
      Card * Deck::deal() {
          int card;
          do {        
              card = random.IRandom(0,51);
          } while(dealt[card] == true);
          dealt[card] = true;
          return &amp;deck[card];
      }
  </code></pre>
  
  <p>test.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Deck.h"
  using namespace std;
  
  int main (){
      Deck * d = new Deck();
      for ( int i = 0; i &lt; 52; i++ ){
          Card * dealt = d-&gt;deal();
          dealt-&gt;printCard();
          cout &lt;&lt; "     ";
      }
      delete d;
  
  }
  </code></pre>