title: C++11 range-based for on a vector of pointers
body: <p>I have just compiled GCC 4.6.0, and I wanted to try the new features out, starting with the range-based for loop.<br />
  The first loop I wanted to change was iterating on a std::vector of pointers. I changed the code to use the new syntax, but it didn't compile.</p>
  <p>I have tried to substitute another for loop, which was on a std::vector of structs, and it compiled and ran perfectly.</p>
  <p>Here is a short test code to show you my problem:</p>
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      std::vector&lt; int &gt; values;
      
      values.push_back(2);
      values.push_back(5);
      values.push_back(8);
      values.push_back(13);
      values.push_back(17);
      
      for (int &amp;n : values)
      {
          std::cout &lt;&lt; n &lt;&lt; &quot;\n&quot;;
      }
      
      std::vector&lt; int* &gt; pointers;
      
      pointers.push_back(new int(2));
      pointers.push_back(new int(5));
      pointers.push_back(new int(8));
      pointers.push_back(new int(13));
      pointers.push_back(new int(17));
      
      for ((int*) &amp;p : values)
      {
          std::cout &lt;&lt; (*p) &lt;&lt; &quot;\n&quot;;
      }
      
      for( unsigned int i = 0; i &lt; pointers.size(); ++i)
      {
          delete pointers[i];
      }
      
      return 0;
  }
  </code></pre>
  <p>When I try to compile it <em>(yes, I give -std=c++0x as a parameter to g++)</em>, it dies with this error:</p>
  <blockquote>
  <p>main.cpp|27|error: found ‘:’ in nested-name-specifier, expected ‘::’</p>
  </blockquote>
  <p>If I comment the lines 27-30 out, it's OK.</p>
  <p>What am I doing wrong? Isn't the pointer-reference declaring syntax right?<br />
  Or is there a limitation of contained types where range-based for loops can be used?</p>