title: Invalid use of non-static data member from within a nested class
body: <p>I'm writing some code with polymorphic inheritance of two classes from a base class all nested within a class like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A
  {
  
      class base
      {
      public:
          virtual void foo();
      };
  
      class B: public base
      {
      public:
          void foo() { cout &lt;&lt; number1; }
      };
  
      class C: public base
      {
      public:
          void foo() { cout &lt;&lt; number2; }
      };
  
  public:
      A(unsigned num): number1(num), number2(num*2)
      {
          if(num &lt; 5)
          {
              a = new B;
          }
          else
          {
              a = new C;
          }
      }
  
      void getNumber() const
      {
          a-&gt;foo();
      }
  
  private:
      const unsigned number1;
      const unsigned number2;
  
      base* a;
  };
  
  int main()
  {
      A object1(1);
      A object2(10);
  
      object1.getNumber();
      object2.getNumber();
  }
  </code></pre>
  
  <p>From what I understand about c++11 and forwards, this should be possible? I know that nested classes post c++11 can access the data members of the class they are nested within as long as they have access to do so, but this seems to work against that. When I compile this I get these errors:</p>
  
  <pre><code>compiler commands: g++ -std=c++14 test.cpp -o t.exe
  
  test.cpp: In member function 'virtual void A::B::foo()':
  test.cpp:17:34: error: invalid use of non-static data member 'A::number1'
               void foo() { cout &lt;&lt; number1; }
                                ^
  test.cpp:45:24: note: declared here
           const unsigned number1;
                      ^
  test.cpp: In member function 'virtual void A::C::foo()':
  test.cpp:23:34: error: invalid use of non-static data member 'A::number2'
               void foo() { cout &lt;&lt; number2; }
                                ^
  test.cpp:46:24: note: declared here
           const unsigned number2;
  </code></pre>
  
  <p>This seems like it should work, as both B and C are nested within A and should have access to data members from A. Why is this? Is there a way to work around this feasibly?</p>