title: C++ error: was not declared in this scope with private after public
body: <p>Attempting to modify the code from <a href="http://kbokonseriousstuff.blogspot.com/2011/09/using-reverse-iterators-with-c11-range.html">this page</a>.</p>
  
  <p>Here's the problem code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;array&gt;
  
  template&lt;class T&gt;
  class const_reverse_wrapper
  {
  public:
      const_reverse_wrapper (const T&amp; cont)
          : container_(cont)
      {
      }
  
      decltype( container_.rbegin() ) begin() const
      {
          return container_.rbegin();
      }
  
      decltype( container_.rend() ) end()
      {
          return container_.rend();
      }
  
  private:
      const T &amp; container_;
  };
  
  template&lt;class T&gt;
  class reverse_wrapper
  {
  public:
      reverse_wrapper (T &amp; cont)
          : container_(cont)
      {
      }
  
      decltype( container_.rbegin() ) begin()
      {
          return container_.rbegin();
      }
  
      decltype( container_.rend() ) end()
      {
          return container_.rend();
      }
  private:
      T &amp; container_;
  };
  
  template&lt;class T&gt;
  const_reverse_wrapper&lt;T&gt; reversed (const T &amp; cont)
  {
      return const_reverse_wrapper&lt;T&gt;(cont);
  }
  
  template&lt;class T&gt;
  reverse_wrapper&lt;T&gt; reverse (T &amp; cont)
  {
      return reverse_wrapper&lt;T&gt;(cont);
  }
  
  int main (int argc, char * argv[])
  {
      std::array&lt;int,4&gt; a = { 1, 2, 3, 4 };
      for (int i : a)
          std::cout &lt;&lt; i;
      return 0;
  }
  </code></pre>
  
  <p>When I compile it, I get these errors:</p>
  
  <pre><code>&gt; g++ -std=c++0x test2.cpp
  test2.cpp:13:15: error: 'container_' was not declared in this scope
  test2.cpp:13:15: error: 'container_' was not declared in this scope
  test2.cpp:18:15: error: 'container_' was not declared in this scope
  test2.cpp:18:15: error: 'container_' was not declared in this scope
  test2.cpp:36:15: error: 'container_' was not declared in this scope
  test2.cpp:36:15: error: 'container_' was not declared in this scope
  test2.cpp:41:15: error: 'container_' was not declared in this scope
  test2.cpp:41:15: error: 'container_' was not declared in this scope
  </code></pre>
  
  <p>When I move the private sections before the public sections in each class, the errors go away.</p>
  
  <pre><code>template&lt;class T&gt;
  class const_reverse_wrapper
  {
  private:                    // &lt;-----
      const T &amp; container_;   // &lt;-----
  public:
      const_reverse_wrapper (const T&amp; cont)
          : container_(cont)
      {
      }
  
      decltype( container_.rbegin() ) begin() const
      {
          return container_.rbegin();
      }
  
      decltype( container_.rend() ) end()
      {
          return container_.rend();
      }
  };
  
  template&lt;class T&gt;
  class reverse_wrapper
  {
  private:              // &lt;-----
      T &amp; container_;   // &lt;-----
  public:
      reverse_wrapper (T &amp; cont)
          : container_(cont)
      {
      }
  
      decltype( container_.rbegin() ) begin()
      {
          return container_.rbegin();
      }
  
      decltype( container_.rend() ) end()
      {
          return container_.rend();
      }
  };
  </code></pre>
  
  <p>I've tried compiling with MinGW GCC 4.6.2 and 4.7.0 and get the same results. Is this a bug, or is there something else going on?</p>