title: Linked List c++ node constructor
body: <p>I was given this code to manipulate to practice Linked Lists, but before I start, there are a few things I don't understand. First of all I thought a default constructor was made by the program itself when there is no constructor written. Here there is a comment saying "default constructor makes an empty list" next to a written constructor. I also don't understand why there is a set of square brackets next to this... { head = NULL; }</p>
  
  <p>But most of all I don't understand this line of code...
       friend ostream&amp; operator&lt;&lt;( ostream&amp; os, const LinkedList &amp;ll );</p>
  
  <p>What does this do?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  class LinkedList
  {
  public:
       LinkedList() { head = NULL; } // default constructor makes an empty list
  
      // functions to aid in debugging
      // -----------------------------
      friend ostream&amp; operator&lt;&lt;( ostream&amp; os, const LinkedList &amp;ll );
      void insertHead( int item );
  
  private:
      class Node // inner class for a linked list node
          {
          public:
              Node( int item, Node *n ) // constructor
              int data; // the data item in a node
              Node *next; // a pointer to the next node in the list
          };
      Node *head; // the head of the list
      };
  
  friend ostream&amp; operator&lt;&lt;( ostream&amp; os, const LinkedList &amp;ll )
       {
       for (Node *current = ll.head; current != NULL; current = current-&gt;next)
           os &lt;&lt; current-&gt;data &lt;&lt; " ";
  return os;
  }
  
  void LinkedList::insertHead( int item ) // insert at head of list
  {
  head = new Node( item, head );
  }
  
  LinkedList::Node::Node( int item, Node *n ) {Node::data = item; next = n;}
  </code></pre>