title: Errors creating std::vector of local structure
body: <pre><code>#include &lt;vector&gt;
  int main() {
      struct st { int a; };
      std::vector&lt;st&gt; v;
      for (std::vector&lt;st&gt;::size_type i = 0; i &lt; v.size(); i++) {
          v.operator[](i).a = i + 1; // v[i].a = i+1;
      }
  }
  </code></pre>
  
  <p>The above code gives the following errors when compiled with GNU g++ compiler.</p>
  
  <pre><code>test.cpp: In function ‘int main()’:
  test.cpp:6:19: error: template argument for ‘template&lt;class _Alloc&gt; class std::allocator’ uses local type ‘main()::st’
  test.cpp:6:19: error:   trying to instantiate ‘template&lt;class _Alloc&gt; class std::allocator’
  test.cpp:6:19: error: template argument 2 is invalid
  test.cpp:6:22: error: invalid type in declaration before ‘;’ token
  test.cpp:7:24: error: template argument for ‘template&lt;class _Alloc&gt; class std::allocator’ uses local type ‘main()::st’
  test.cpp:7:24: error:   trying to instantiate ‘template&lt;class _Alloc&gt; class std::allocator’
  test.cpp:7:24: error: template argument 2 is invalid
  test.cpp:7:37: error: expected initializer before ‘i’
  test.cpp:7:44: error: ‘i’ was not declared in this scope
  test.cpp:7:50: error: request for member ‘size’ in ‘v’, which is of non-class type ‘int’
  test.cpp:8:20: error: request for member ‘operator[]’ in ‘v’, which is of non-class type ‘int’
  </code></pre>
  
  <p>Why I am not able to create vector of structures?</p>