title: C++ Passing ostream as parameter
body: <p>I'm working on a homework project for a virtual rolodex that has called for a main class, a rolodex class, and a card class. To output the contents of all of the "cards" to the console, the assignment says that main() should call a show(...) function in the rolodex class, passing it an ostream and show(...) then iterates over the cards, calling each of their showCard() functions. The actual showing is done by the card objects' showCard() function, showing on the provided ostream.</p>
  
  <p>What I don't understand is why an ostream would/should be passed anywhere. Seems like the assignment is calling for something like this:</p>
  
  <pre><code>main() {
     Rolodex myRolodex; 
     ostream myStream; 
     myRolodex.show(myStream); 
  }
  
  void Rolodex::show(ostream&amp; theStream) {
     //for each card 'i' in the Rolodex...
     myCard[i].show(theStream);
  }
  
  void Card::show(ostream&amp; theStream) {
     theStream &lt;&lt; "output some stuff" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>instead of something like this:</p>
  
  <pre><code>main() {
     Rolodex myRolodex;  
     myRolodex.show(); //no ostream passed 
  }
  
  void Rolodex::show() {
     //for each card 'i' in the Rolodex...
     myCard[i].show();//no ostream passed
  }
  
  void Card::show() {
     cout &lt;&lt; "output some stuff" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Am I either misunderstanding the use of ostream as a parameter or missing some other obvious reason to pass an ostream down the stream like that?</p>