title: A template declaration cannot appear at block scope
body: <p>I'm learning Lipmann and I'm only studying. I'm trying here to write a code that will return a minimal element in a vector. When I compile my code in Codeblocks, it says: "A template declaration cannot appear at block scope". Here is the code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      template &lt;class elemType&gt;
      elemType save;
      elemType min (const std::vector&lt;elemType&gt; &amp;vec) {
        std::vector&lt;elemType&gt;::iterator it = vec.begin(), end_it = vec.end();
        std::vector&lt;elemType&gt;::iterator iter = std::next(it, 1);
        for ( ; it != end_it; it++ ) {
          if ( *it &lt; *(it + 1) ) {
            save = *it;
          }
          if (save &lt; *it) {
            save = *it;
          }
        }
      };
  
      int massiv[10] = {35, 66, 98, 15, 32, 41, 24, 90, 55, 100};
      std::vector&lt;int&gt; vec_train(massiv,massiv+10);
  
  
      min(vec_train);
      return 0;
  }
  </code></pre>