title: How to overload << operator without friend function
body: <p>I am trying to overload &lt;&lt; operator to print Currency (user defined type)</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct Currency
  {
    int Dollar;
    int Cents;
  
    ostream&amp; operator&lt;&lt; (ostream &amp;out)
    {
      out &lt;&lt; "(" &lt;&lt; Dollar &lt;&lt; ", " &lt;&lt; Cents &lt;&lt; ")";
      return out;
    }
  };
  
  
  
  template&lt;typename T&gt;
  void DisplayValue(T tValue)  
  {
     cout &lt;&lt; tValue &lt;&lt; endl;
  }
  
  int main() {
  
  Currency c;
  c.Dollar = 10;
  c.Cents = 54;
  
  DisplayValue(20); // &lt;int&gt;
  DisplayValue("This is text"); // &lt;const char*&gt;
  DisplayValue(20.4 * 3.14); // &lt;double&gt;
  DisplayValue(c); // Works. compiler will be happy now. 
  return 0;
  }
  </code></pre>
  
  <p>But getting the following error. </p>
  
  <pre class="lang-none prettyprint-override"><code>prog.cpp: In instantiation of ‘void DisplayValue(T) [with T = Currency]’:
  prog.cpp:34:16:   required from here
  prog.cpp:22:9: error: cannot bind ‘std::ostream {aka std::basic_ostream&lt;char&gt;}’ lvalue to ‘std::basic_ostream&lt;char&gt;&amp;&amp;’
      cout &lt;&lt; tValue &lt;&lt; endl;
           ^
  In file included from /usr/include/c++/4.8/iostream:39:0,
                   from prog.cpp:1:
  /usr/include/c++/4.8/ostream:602:5: error:   initializing argument 1 of ‘std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp;, const _Tp&amp;) [with _CharT = char; _Traits = std::char_traits&lt;char&gt;; _Tp = Currency]’
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp; __os, const _Tp&amp; __x)
       ^
  </code></pre>
  
  <p>Can anyone help me if i am missing any thing or doing anything wrong here?</p>