title: C++ Inner class not able to access Outer class's members
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/486099/can-inner-classes-access-private-variables">Can inner classes access private variables?</a><br>
    <a href="https://stackoverflow.com/questions/11405069/inner-class-accessing-outer-class">Inner class accessing outer class</a>  </p>
  </blockquote>
  
  
  
  <p>I have some simple classes nested so they can interact with a variable without extra inputs, yet my compiler gives me an error. How would I allow for them to interact without using &amp;time as function input or having the variable &amp;time inside of the Vect class?</p>
  
  <p>I tried using the same logic where you can have data accessed that is just in the code, at the same place as function prototypes, but is instead wrapped in a class. This works fine for anything I've used except other classes. Can anyone explain why?</p>
  
  <p>I have marked the places that use the problematic time variable with comment lines like the one before the define.</p>
  
  <pre><code>/*********/
  #define MAX_POLY 3
  
  class Container
  {
  public:
      Container(void);
      ~Container(void);
  
      float time;/*********/
      class Vect
      {
          float P[MAX_POLY],iT;
      public:
          Vect(void){iT = 0.0f;P = {0,0,0};}
          ~Vect(void);
  
          float GetPoly(int n){return P[n];}
          float Render(void)
          {
              float t = time - iT;/*********/
              float temp[2] = {0,0};
              for(int n=0;n&lt;MAX_POLY;n++)
              {
                  temp[0] = P[n];
                  for(int m=0;m&lt;n;m++)
                      temp[0] *= t;
                  temp[1] += temp[0];
              }
              return temp[1];
          }
          void SetPoly(int n,float f)
          {
              float t = time-iT;/*********/
              P[0] = P[2]*t*t + P[1]*t + P[0];
              P[1] = 2*P[2]*t + P[1];
              //P[2] = P[2];
              P[n] = f;
              iT = time;/*********/
          }
      }X;
  };
  
  int main()
  {
      Container Shell;
      Shell.X.SetPoly(0,5);
      Shell.X.SetPoly(1,10);
      Shell.X.SetPoly(2,-1);
      for(int n=0;n&lt;10;n++)
      {
          Shell.time = (float)n;
          cout &lt;&lt; n &lt;&lt; " " &lt;&lt; Shell.X.Render() &lt;&lt; endl;
      }
      system("pause");
      return 0;
  }
  </code></pre>