title: Using a custom class with a custom template container
body: <p>I'm trying to define a custom template container, and then add custom class objects (Students) into it. Here's my code:</p>
  
  <pre><code>class Student{
  public:
      string subject;
      Student(string _subject){
          subject = _subject;
      }
  };
  </code></pre>
  
  <p>And here's my LinkedList template code</p>
  
  <pre><code>template &lt;class T&gt;
  class LinkedList{
  
  private:
      struct Node{
          Node *next;
          T value;
      };
      Node *root;
      Node *curr;
      int count;
  
  public:
      LinkedList() : count(0), root(NULL){}
      void add(T val){
          if (root == NULL){
              root = new Node;
              root-&gt;value = val;
              root-&gt;next = NULL;
              curr = root;
          }
          else{
              curr-&gt;next = new Node;
              curr = curr-&gt;next;
              curr-&gt;value = val;
              curr-&gt;next = NULL;
          }
          count++;
      }
  
      void print(){
          for (Node *itr=root; itr != NULL; itr = itr-&gt;next){
              cout &lt;&lt; itr-&gt;value &lt;&lt; endl;
          }
      }
  };
  
  int main(){
      LinkedList&lt;Student&gt; a;
      Student sam("Math");
      a.add(sam)
  }
  </code></pre>
  
  <p>When I run it, I get</p>
  
  <blockquote>
    <p>linkedlist.cpp: In constructor ‘LinkedList::Node::Node()’:
    linkedlist.cpp:27:   instantiated from ‘void LinkedList::add(T) [with T = Student]’</p>
    
    <p>linkedlist.cpp:133:   instantiated from here</p>
    
    <p>linkedlist.cpp:27: error: no matching function for call to ‘Student::Student()’
    linkedlist.cpp:18: note: candidates are: Student::Student(std::string)</p>
    
    <p>linkedlist.cpp:15: note:                 Student::Student(const Student&amp;)
    linkedlist.cpp: In member function ‘void LinkedList::add(T) [with T = Student]’:</p>
    
    <p>linkedlist.cpp:40: note: synthesized method ‘LinkedList::Node::Node()’ first required here </p>
  </blockquote>
  
  <p>I have no clue what that error really means, and what it's asking me to do. If I do this instead:</p>
  
  <pre><code>int main(){
      LinkedList&lt;Student*&gt; a;
      Student sam("Math");
      a.add(&amp;sam);
  }
  </code></pre>
  
  <p>It works just fine.</p>
  
  <p>But storing references to objects is not what I'm after. How can I get my LinkedList to make copies of the object I wish to add to it?</p>
  
  <p>Thanks in advance!</p>