title: How can I fix this error `conversion from const_iterator to non-scalar type`?
body: <p>can someone explain what is the mention of this error:  </p>
  
  <blockquote>
    <p>conversion from 'std::vector&lt;int, std::allocator&lt;int&gt; &gt;::const_iterator {aka __gnu_cxx::__normal_iterator&lt;const int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;}' to non-scalar type 'std::vector&lt;int, std::allocator&lt;int&gt; &gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int, std::allocator&lt;int&gt; &gt; &gt;}' requested  </p>
  </blockquote>
  
  <p>given the following class:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using std::vector;
  using std::ostream;
  
  template&lt;class T&gt;
  class Gen {
      vector&lt;T&gt; array;
  public:
      explicit Gen(int size);
      template&lt;class S&gt;
      friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Gen&lt;S&gt;&amp; g);
  };
  
  template&lt;class T&gt;
  Gen&lt;T&gt;::Gen(int size) {
      for (int i = 0; i &lt; size; i++) {
          this-&gt;array.push_back(T());
      }
  }
  
  template&lt;class T&gt;
  ostream&amp; operator&lt;&lt;(ostream&amp; os, const Gen&lt;T&gt;&amp; g) {
      for (typename vector&lt;T&gt;::iterator it = g.array.begin(); it != g.array.end();
              it++) { // ****** error ********
          os &lt;&lt; *it &lt;&lt; " ";
      }
      return os;
  }
  
  int main() {
      Gen&lt;int&gt; g(3);
      std::cout &lt;&lt; g &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>how can I fix that?</p>