title: overloading left shift operator
body: <p>I have researched and found out that when you want to overload the output stream operator for cout, then the correct way to go about it is to do it this way:</p>
  
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const T&amp; obj)
  </code></pre>
  
  <p>This function must be defined outside the class since whats going on here is that the operator&lt;&lt; is actually a friend function defined in ostream and you are making use of that. But, the question is, how exactly is this function being defined in ostream? Since this function takes 2 parameters and the second parameter is user-defined, there is no way that they can guess what is coming there. </p>
  
  <p>Overloading for a class specific should look like this:</p>
  
  <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const MyClass&amp; obj)
  </code></pre>
  
  <p>How does the compiler/library take a generic definition for the second parameter, especially since there is no such thing as a generic class (such as Object in Java) in C++?</p>