title: C++ Deque Custom Class Templating
body: <p>I have a class "board" that I am trying to put a deque member in.  I wrote the code with an int object for the deque and everything worked fine, so I think it is a problem with setting the Template for the custom class, but I have never done this in C++.</p>
  
  <p>board.h:</p>
  
  <pre><code> #ifndef __board_h__
   #define __board_h__
   using namespace std;
  
   #include &lt;deque&gt;
   #include "noble_card.h"
   class board;
  
   class board
  {
      public: deque&lt;noble_card&gt; line;
      public: board();
      public: ~board();
  };
  
  #endif
  </code></pre>
  
  <p>board.cpp:</p>
  
  <pre><code>#include &lt;deque&gt;
  #include "noble_card.h"
  
  board::board() {
      deque&lt;noble_card&gt; line;
  }
  
  board::~board() {}
  </code></pre>
  
  <p>I think I may have a problem with the construction method here, as deque is erroring out on so many things I am having trouble tracking it down.</p>
  
  <p>noble_card.h:</p>
  
  <pre><code>#include &lt;string&gt;
  
  #ifndef __noble_card_h__
  #define __noble_card_h__
  
  #include "board.h"
  
  class noble_card
  {
      public: string name;
      public: int id;
      public: int vp;
  
      public: noble_card(int _vp);
      public: ~noble_card();
  };
  
  #endif
  </code></pre>
  
  <p>noble_card.cpp:</p>
  
  <pre><code>#include "noble_card.h"
  
  noble_card::noble_card(int _vp) {
          this-&gt;vp = _vp;
  }
  
  noble_card::~noble_card() {
  }
  </code></pre>
  
  <p>Now, the problem comes when I try to push elements onto this deque, i have a for loop like such:</p>
  
  <pre><code>board b;
  for (unsigned i = 0; i &lt; 12; i++) {
            noble_card nc(i);
            b-&gt;line.push_back( nc );
  }
  </code></pre>
  
  <p>I keep getting assignment operator could not be generated, copy constructor could not be generated, and std::deque : 'noble_card' is not a valid template type argument for parameter '_Ty' (board.h).  I am assuming this is because I haven't templated my classes and overridden the copy/constructor methods to tell the deque how to sort/remove/alloc/copy this type of class.  I'm basically just trying to get a custom c++ class to be used in a deque and it is a lot more complicated than C# and other standard libraries I've used where you just push it on there and it takes care of it.</p>
  
  <p>EDIT:</p>
  
  <pre><code>#ifndef __noble_card_h__
  #define __noble_card_h__
  using namespace std;
  
  class noble_card {
      public: char* name;
      public: int id;
      public: int vp;
  
      public: noble_card(char* _name, int _id, int _vp) : name(_name), id(_id), vp(_vp) {}
  };
  
  #endif
  </code></pre>
  
  <p>Setting up noble_card.h this way seems to satisfy the requirements for the copy/alloc/constructor for deque.  I still don't fully understand it as it seems to be shorthand, so if anyone could expand on line 10 I'd much appreciate it.  For now This change has me moving forward.</p>