title: Print linked list using operator overloading
body: <p>I am working on a singly linked list.  Several components of the list are not yet set up in main.  However, I am working out the definitions in the class and would like to overload the cout &lt;&lt; operator to print the contents of the list.  </p>
  
  <p>The last definition in queue.cpp is where I am trying to have it print each node 1 by 1.  I Successfully overloaded both cin and cout to work with the Game class, but I need to get cout working with the Queue class to print the nodes.  I appreciate all the help/advice and feedback.</p>
  
  <p>Here is my code so far:</p>
  
  <p>queue.h</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  #ifndef QUEUE_H_
  #define QUEUE_H_
  
  class Game
  {
  private:
      std::string title;
  public:
      Game(const std::string &amp; s);
      Game(); //default constructor
      ~Game();    //destructor 
      friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Game &amp; g);  //allows cout &lt;&lt; to be used object
      friend std::istream &amp; operator&gt;&gt;(std::istream &amp; is, Game &amp; g);        //allows cin &gt;&gt; to be used with object
  };
  
  class Queue
  {
  private:
      struct Node
      {
          Game game;      //data stored in the node
          struct Node * next; //pointer to next node
      };
  //  enum {Q_SIZE = 10};
      Node * front;   //pointer to front of Queue
      Node * rear;    //pointer to rear of Queue
      int items;      //current number of games in Queue
      const int qsize;    //max number of games in Queue
  public:
      Queue(int qs);      //create a queue with a qs limit
  //  Queue();
      ~Queue();
      bool isempty() const;
      bool isfull() const;
      int queuecount() const;
      bool enqueue(const Game &amp; game);    //add game to end
      bool dequeue(Game &amp; game);          //remove game from front
      friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Queue &amp; q);
  };
  #endif
  </code></pre>
  
  <p>queue.cpp</p>
  
  <pre><code>#include "queue.h"
  
  using namespace std;
  
  
  //Game methods
  Game::Game(const string &amp; s)
  {
      title = s;
  }
  
  Game::Game()    //default constructor can be blank or empty
  {
  //  title = '\0';  //NULL
  //  title = "JEGORRRRRE."; 
  }
  
  Game::~Game()
  {
      cout &lt;&lt; " destructor called" &lt;&lt; endl;
  }
  
  ostream &amp; operator&lt;&lt;(ostream &amp; os, const Game &amp; g)
  {
      os &lt;&lt; g.title;
      return os;
  }
  
  istream &amp; operator&gt;&gt;(istream &amp; is, Game &amp; g)
  {
      getline(cin, g.title); //code for reading line into a string object (pg. 131)
      return is;
  }
  
  
  //Queue methods
  Queue::Queue(int qs)  : qsize(qs) //initialize qsize to qs because qsize is a const; must be done when the object is created
  {
      front = rear = NULL;
      items = 0;
  }
  
  Queue::~Queue()
  {
      Node * temp;
      while (front != NULL)       //while queue is not yet empty
      {
          temp = front;               //save address of front item
          front = front -&gt;next;       //reset pointer to next item
          delete temp;                    //delete former front
      }
  }
  
  bool Queue::isempty() const
  {
      return items == 0;
  }
  
  bool Queue::isfull() const
  {
      return items == qsize;
  }
  
  int Queue::queuecount() const
  {
      return items;
  }
  
  bool Queue::enqueue(const Game &amp; game)
  {
      if (isfull())
          return false;
      Node * add = new Node;  //creates node
      add-&gt;game = game;       //add accesses game member of struct and sets it to game
      add-&gt;next = NULL;       //add accesses next member of struct and sets it to NULL
      items++;                //increments the item count
      if (front == NULL)  //if queue is empty 
          front = add;    //place at front
      else
          rear-&gt;next = add; //else place at rear; in this case rear accesses the next member of struct and assigns the newly created node at next
      rear = add;     //rear points to new node; this line --&gt; Node * add = new Node;
      return true;
  }
  
  bool Queue::dequeue(Game &amp; game)    //place front item into item variable and remove from queue
  {
      if (front == NULL)
          return false;
      game = front-&gt;game;         //set item to first item in queue
      items--;                                
      Node * temp = front;            //save location of first item
      front = front-&gt;next;            //reset front to next item
      delete temp;                        //delete former first item
      if (items == 0)
          rear = NULL;
      return true;
  }
  
  ostream &amp; operator&lt;&lt;(ostream &amp; os, const Queue &amp; q)//figure out how to print nodes..
  {
      //
      //return os;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "queue.h"
  
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "Top Video Games of all Time\n___________________________"
          &lt;&lt; "\nenter max number of games: \n";
      int q_size;
      (cin &gt;&gt; q_size).get();
      Queue list(q_size);
  
      Game temp;
  
      for (int c = 1; c &lt; 11; c++)
      {
          cout &lt;&lt; "Enter game title " &lt;&lt; c &lt;&lt; endl;   
          cin &gt;&gt; temp;
          list.enqueue(temp);
      }
  
  //  cout &lt;&lt; list;
  
      cout &lt;&lt; "\n\n\n\n\n\n\n";
      system("pause");
      return 0;
  }
  </code></pre>