title: c++: Printing a STL list
body: <p>I was going through STL list and I tried to implement the list as type class instead of int or any other data type. Below is the code I tried to compile</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  class AAA {
  public:
      int x;
      float y;
      AAA();
  };
  
  AAA::AAA() {
      x = 0;
      y = 0;
  }
  
  int main() {
      list&lt;AAA&gt; L;
      list&lt;AAA&gt;::iterator it;
      AAA obj;
  
      obj.x=2;
      obj.y=3.4;
      L.push_back(obj);
  
      for (it = L.begin(); it != L.end(); ++it) {
          cout &lt;&lt; ' ' &lt;&lt; *it;
      }
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>But it is giving error in the line:</p>
  
  <pre><code>cout&lt;&lt;' '&lt;&lt;*it;
  </code></pre>
  
  <p>and the error is</p>
  
  <pre><code>In function 'int main()':
  34:13: error: cannot bind 'std::basic_ostream&lt;char&gt;' lvalue to    'std::basic_ostream&lt;char&gt;&amp;&amp;'
  In file included from /usr/include/c++/4.9/iostream:39:0,
               from 1:
  /usr/include/c++/4.9/ostream:602:5: note: 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 = AAA]'
   operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp; __os, const _Tp&amp; __x)
   ^
  </code></pre>
  
  <p>Actually I want to print the contents of the list using the code above.Can somebody help me in solving this??</p>