title: Visibility of privately inherited typedefs to nested classes
body: <p>In the following example (apologies for the length) I have tried to isolate some unexpected behaviour I've encountered when using nested classes within a class that privately inherits from another. I've often seen statements to the effect that there is nothing special about a nested class compared to an unnested class, but in this example one can see that a nested class (at least according to GCC 4.4) can see the public typedefs of a class that is privately inherited by the closing class. </p>
  
  <p>I appreciate that typdefs are not the same as member data, but I found this behaviour surprising, and I imagine many others would, too. So my question is twofold:</p>
  
  <ol>
  <li>Is this standard behaviour? (a decent explanation of why would be very helpful)</li>
  <li>Can one expect it to work on most modern compilers (i.e., how portable is it)?</li>
  </ol>
  
  <hr>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Base {
    typedef int priv_t;
    priv_t priv;
  public:
    typedef int pub_t;
    pub_t pub;
    Base() : priv(0), pub(1) {}
  };
  
  class PubDerived : public Base {
  public:
    // Not allowed since Base::priv is private
    // void foo() {std::cout &lt;&lt; priv &lt;&lt; "\n";}
  
    class Nested {
      // Not allowed since Nested has no access to PubDerived member data
      // void foo() {std::cout &lt;&lt; pub &lt;&lt; "\n";}
  
      // Not allowed since typedef Base::priv_t is private
      // void bar() {priv_t x=0; std::cout &lt;&lt; x &lt;&lt; "\n";}
    };
  
  };
  
  class PrivDerived : private Base {
  public:
    // Allowed since Base::pub is public
    void foo() {std::cout &lt;&lt; pub &lt;&lt; "\n";}
  
    class Nested {
    public:
      // Works (gcc 4.4 - see below)
      void fred() {pub_t x=0; std::cout &lt;&lt; x &lt;&lt; "\n";}
    };
  };
  
  int main() {
  
    // Not allowed since typedef Base::priv_t private
    // std::cout &lt;&lt; PubDerived::priv_t(0) &lt;&lt; "\n";
  
    // Allowed since typedef Base::pub_t is inaccessible
    std::cout &lt;&lt; PubDerived::pub_t(0) &lt;&lt; "\n"; // Prints 0
  
    // Not allowed since typedef Base::pub_t is inaccessible
    //std::cout &lt;&lt; PrivDerived::pub_t(0) &lt;&lt; "\n";
  
    // Works (gcc 4.4)
    PrivDerived::Nested o;
    o.fred(); // Prints 0
    return 0;
  }
  </code></pre>