title: Protected member access compiles differently in g++ and Visual Studio
body: <p>I have the following code with two levels of inheritance of class templates:</p>
  
  <pre><code>template &lt;typename FIELD&gt;
  class Class1
  {
  protected:
      int n;
      FIELD data1;
  public:
      Class1();
      virtual ~Class1() {}
  };
  
  template &lt;typename FIELD&gt; class Class3;
  
  template &lt;typename FIELD&gt;
  class Class2 : public Class1&lt;FIELD&gt;
  {
  protected:
      using Class1&lt;FIELD&gt;::n;
      FIELD data2;
  public:
      Class2();
      virtual ~Class2() {}
      int Method(Class3&lt;FIELD&gt; &amp;) const;
  };
  
  template &lt;typename FIELD&gt;
  class Class3 : public Class2&lt;FIELD&gt;
  {
  protected:
      using Class1&lt;FIELD&gt;::n;
      FIELD data3;
  public:
      Class3();
      virtual ~Class3() {}
  };
  
  template &lt;typename FIELD&gt;
  int Class2&lt;FIELD&gt; :: Method(Class3&lt;FIELD&gt; &amp; U) const
  {
      U = Class3&lt;FIELD&gt;();
      int g = U.n;
      return g;
  }
  
  template class Class2&lt;double&gt;;
  </code></pre>
  
  <p>I compile this into an object file in Ubuntu using command:
  <code>g++ -c -std=c++11 -Wall -Wfatal-errors -o Test.o Test.cpp</code>
  and no error whatsoever is generated, the object file is created just fine!</p>
  
  <p>However, when I try to compile the very same code from within Visual Studio using <strong>Ctrl+F7</strong>, I get C2248 error that reads:
  'Class3::n': cannot access protected member declared in class 'Class3'</p>
  
  <p>Is there a bug in one of the compilers? Which one follows standard? Despite my faith in g++, I'm inclined to think that VS is more correct in this case since variable <code>n</code> should be accessed by <code>Class2</code> only from <code>Class1</code> (since it is base class for <code>Class2</code>) but not from <code>Class3</code>.</p>
  
  <p>Note that I need to add line <code>friend int Class2::Method(Class3&lt;FIELD&gt; &amp;) const;</code>
  within <code>Class3</code> declaration to bypass C2248 error in VS.</p>
  
  <p>Thanks for all the answers!</p>