title: How to overload operator << with linked list?
body: <p>For class, I am trying to overload the &lt;&lt; operator so I can print out an object I created.  I declared and added to this</p>
  
  <pre><code>WORD you; //this is a linked list that contains 'y' 'o' 'u'
  </code></pre>
  
  <p>and I want to do this</p>
  
  <pre><code>cout &lt;&lt; you; //error: no operator "&lt;&lt;" matches theses operands
  </code></pre>
  
  <p>I have to overload the insertion operator as a friend function with chaining to print a word.</p>
  
  <p>I have declared and defined the overloaded function, but it still does not work.  Here is the class declaration file, followed by the .cpp file with the function</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  #pragma once
  
  class alpha_numeric //node
  {
  public:
  char symbol; //data in node
  alpha_numeric *next;//points to next node
  };
  
  class WORD
  {
  public:
  WORD(); //front of list initially set to Null
  //WORD(const WORD&amp; other);
  bool IsEmpty(); //done
  int Length();
  void Add(char); //done
  void Print(); //dont
  //void Insert(WORD bword, int position);
  //WORD operator=(const string&amp; other);
  
  friend ostream &amp; operator&lt;&lt;(ostream &amp; out, alpha_numeric *front);//******************&lt;-----------------
  
  private:
  alpha_numeric *front; //points to the front node of a list
  int length;
  
  }; 
  </code></pre>
  
  <p>In the .cpp file, I put <code>*front</code> in the parameter because it said <code>front</code> was not defined when I tried to use it inside the function, even though I declared it in the class.  I then tried this. I have no clue if it is correct.</p>
  
  <pre><code>ostream &amp; operator&lt;&lt;(ostream &amp; out, alpha_numeric *front)
  {
  alpha_numeric *p;
  for(p = front; p != 0; p = p -&gt; next)
  {
      out &lt;&lt; p -&gt; symbol &lt;&lt; endl;
  }
  }
  </code></pre>