title: Pointer to dynamic array of pointers to objects
body: <p>Card class header   </p>
  
  <pre><code>class card {
  
  public: 
  
  string rtn_suit() { return suit; }
  int rtn_rank()    { return rank; }
  void set_suit(string new_suit){ suit = new_suit; }
  void set_rank(int new_rank) { rank = new_rank; }
  
  card();
  card(string suit, int rank);
  card(const card&amp; copyCARD);
  ~card();
  
  private:
  string suit;
  int rank;
  
  };
  
  #endif
  </code></pre>
  
  <p>card.cpp</p>
  
  <pre><code>#include "card.h"
  card::card()
  {
  set_suit("default");
  set_rank(0);
  }
  card::card(string new_suit, int new_rank)
  {
  // allows for using private class member variables
  set_suit(new_suit); // can be anything (string)
  set_rank(new_rank); // anticipating simple number ranking (int) 
  }
  
  card::~card() {}
  </code></pre>
  
  <p>Deck class header</p>
  
  <pre><code>class deck {
  
  public:
  
  static const int default_cap = 52;
  
  void addCard(card *new_card);
  
  deck &amp; operator=(const deck &amp;sourceDECK);
  
  void deckPrint();
  
  // ----------------------------------------------------
  
  deck(int init_cap = default_cap);
  deck(const deck&amp; sourceDECK);
  ~deck(){ delete [] decklist ; }
  
  
  private:
  card *decklist;
  int used;
  int capacity;
  
  };
  
  #endif
  </code></pre>
  
  <p>deck class</p>
  
  <pre><code> deck::deck(int init_cap)
   {
  card **decklist = new card*[init_cap];
  
   for(int i=0;i&lt;init_cap;i++)
    {
        decklist[i]=new card;
    }
  
  capacity = init_cap;
  used=0;
  }
  
  deck::deck(const deck&amp; sourceDECK)
  {
  card **newDECK;
  
  if (capacity != sourceDECK.capacity)
  {
  
      newDECK = new card*[sourceDECK.capacity];
  
      for(int i=0;i&lt;sourceDECK.capacity;i++)   {   newDECK[i]=new card();  }
  
      decklist = /*reinterpret_cast&lt;card*&gt;(*/newDECK/*)*/;
  
      capacity = sourceDECK.capacity;
  }
  
  used = sourceDECK.used;
  copy(sourceDECK.decklist, sourceDECK.decklist+ used, decklist);
  
  }
  deck&amp; deck::operator= (const deck&amp; sourceDECK)
  {
  if (this == &amp;sourceDECK)
  
      return *this;
  
  
  card ** newDECK;
  if (capacity != sourceDECK.capacity)
  {
      newDECK = new card*[sourceDECK.capacity];
  
      for(int i=0;i&lt;sourceDECK.capacity;i++)   {   newDECK[i]=new card();   }
      for (int i=0; i&lt;capacity; i++)           {   delete     &amp;decklist[i];     }
      delete [ ] decklist; 
      decklist = /*reinterpret_cast&lt;card*&gt;(*/newDECK/*)*/;
      capacity = sourceDECK.capacity;
  }
  
  // Copy the data from the source array:
  
  used = sourceDECK.used;
  copy(sourceDECK.decklist, sourceDECK.decklist + used, decklist);
  
  return *this;
  }
  
  
  void deck::addCard(card* new_card)
  {
  //------- Not using vectors----
  //deckList.push_back(new_card);
  //cout &lt;&lt; "Card added."&lt;&lt;endl;
  
  decklist[used] = new_card;
  
  //decklist[used].set_rank(new_card-&gt;rtn_rank());
  
  //decklist[used].set_suit(new_card-&gt;rtn_suit());
  
  ++used;
  
  cout &lt;&lt; "Card added."&lt;&lt;endl;
    }
  
  void deck::deckPrint()
   {
  if ( capacity &gt; 0 ) 
  {
  for(int i = 0; i &lt; capacity; i++)
               {
                 cout &lt;&lt; "----------"&lt;&lt;endl;
                 cout &lt;&lt; decklist[i].rtn_rank() &lt;&lt; " ";
                 cout &lt;&lt; decklist[i].rtn_suit() &lt;&lt; endl;
                 cout &lt;&lt; "----------"&lt;&lt;endl;
               }
  }
  else\
  {
      cout &lt;&lt; "There are no cards in the deck."&lt;&lt;endl;
  }
   }
  </code></pre>
  
  <p>And lastly a main()</p>
  
  <pre><code>int main ()
  {
  string new_suit, del_suit;
  int new_rank, del_rank;
  
  deck newDeck;
  
  card *temp_card;
  
  
              cout&lt;&lt;"Enter the card's suit: ";
              cin&gt;&gt;new_suit;
              cout&lt;&lt;endl&lt;&lt;"Enter the card's rank: ";
              cin&gt;&gt;new_rank;
  
              cin.clear();
              cin.ignore(1000, '\n');
  
  
          temp_card = new card(new_suit, new_rank);
  
          newDeck.addCard(temp_card);
  
  
          newDeck.deckPrint();
  
  
  return 0;
  
  }
  </code></pre>
  
  <p>Somewhere, somehow I am not initializing or allocating properly. Or maybe I screwed up the pointers.... </p>
  
  <p>As is, will not compile due to:</p>
  
  <p>error C2679: binary '=' : no operator found which takes a right-hand operand of type 'card *' (or there is no acceptable conversion)
  \projects\cards\cards\card.h(27): could be 'card &amp;card::operator =(const card &amp;)' while trying to match the argument list '(card, card *)'</p>
  
  <p>If I use (currently commented out) a 'deeper copy' aka:</p>
  
  <pre><code>decklist[used].set_rank(new_card-&gt;rtn_rnk());
  </code></pre>
  
  <p>it will throw the error in deckPrint()</p>
  
  <p>I originally wrote this with vectors for a simple card class implementation and then we started learning about dynamic arrays - and I got the bright idea to try and throw pointers in the mix. Again, this is not homework - this is for personal growth.</p>
  
  <p>If there is a tutorial out there that I missed which clearly outlines what I am trying to do, feel free to point me towards that also - I have poured over the top 30 google results and tons of posts here. Half the time people recommend using vectors, which again is not my goal.</p>
  
  <p>Thanks for your time, I know it is lengthy. </p>