title: Question about vector iterator in template functions
body: <p>I'm trying to learn the STL library and I'm having a weird problem. This code compiles perfectly:</p>
  
  <pre><code>void Show(vector&lt;int&gt; myvec)
  {
      vector&lt;int&gt;::iterator it;
      cout &lt;&lt; "Vector contains:";
      for( it = myvec.begin(); it &lt; myvec.end(); it++) 
      {
           cout &lt;&lt; " " &lt;&lt; *it;
      }
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>while this one gives me an error message at compile time:</p>
  
  <pre><code>template &lt;class T&gt; 
  void Show2(vector&lt;T&gt; myvec)
  {
      vector&lt;T&gt;::iterator it;
      cout &lt;&lt; "Vector contains:";
      for( it = myvec.begin(); it &lt; myvec.end(); it++)
      {
           cout &lt;&lt; " " &lt;&lt; *it;
      }
      cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>$ g++ hello.cpp
  hello.cpp: In function ‘void Show2(std::vector&lt;T, std::allocator&lt;_Tp1&gt; &gt;)’:
  hello.cpp:19: error: expected ‘;’ before ‘it’
  hello.cpp:21: error: ‘it’ was not declared in this scope
  </code></pre>
  
  <p>It seems a very simple mistake, but I couldn't find it. </p>