title: Crash when assigning a pointer to the head of a circularly linked list
body: <p>I am doing programming project 6 of chapter 13 of <em>Problem Solving With C++ Global Edition</em> by Savitch. I am trying to overload the <code>&lt;&lt;</code> operator to print the list. It works up to the point where my walker pointer is assigned to the value of the head pointer for the 2nd time, making it impossible for me to use the list as a circularly linked list which is the project requirement. I've recreated the most basic form of the source of the crash here:</p>
  <p>Suitors.h file:</p>
  <pre><code>#include &lt;iostream&gt;
  
  struct Suitor {
      int number;
      Suitor *link;
  };
  
  class Suitors {
  private:
      Suitor *head=nullptr;
      int size=0;
  public:
      //Constructors
      Suitors(int sizePar);
      ~Suitors(); //Destructor
  
      //Print list
      friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; outs, const Suitors&amp; list);
  };
  </code></pre>
  <p>Suitors.cpp File:</p>
  <pre><code>#include &quot;Suitors.h&quot;
  
  Suitors::Suitors(int sizePar) {
      Suitor *tempPtr = new Suitor;
      size = sizePar;
      for (int i=0; i&lt;size; i++) {
          if (head==nullptr) {
              head = tempPtr;
          }
          tempPtr-&gt;number = i+1;
          if (i==size-1) {
              tempPtr-&gt;link = head;
          }
          else {
              tempPtr-&gt;link = new Suitor;
          }
          tempPtr = tempPtr-&gt;link;
      }
  }
  
  Suitors::~Suitors() {
      Suitor *walker1 = head, *walker2 = head;
      for (int i=0; i&lt;size; i++) {
          walker1 = walker1-&gt;link;
          delete walker2;
          walker2 = walker1;
      }
      head = nullptr;
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; outs, const Suitors&amp; list) {
      Suitor *walker = list.head;
      walker = walker-&gt;link;
      walker = list.head;
  
  
      /*
      for (int i=0; i&lt;list.size; i++) {
          outs &lt;&lt; walker-&gt;number &lt;&lt; &quot; &quot;;
          walker = walker-&gt;link;
      }
       */
  }
  </code></pre>
  <p>main.cpp file:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &quot;Suitors.h&quot;
  
  void project6();
  
  int main() {
      std::cout &lt;&lt; &quot;Hello, World!&quot; &lt;&lt; std::endl;
      project6();
      return 0;
  }
  
  void project6() {
      Suitors six(6);
      std::cout &lt;&lt; six &lt;&lt; std::endl;
  }
  </code></pre>
  <p>I've trimmed down the &lt;&lt; operator overloading to just what creates the error. walker is set to the list head, then advanced a node, then set back to the list head, causing the error. The desired behavior is to be able to set walker to the head node more than once.</p>