title: C++ Nested classes forward declaration error
body: <p>I am trying to declare and use a class B inside of a class A
  and define B outside A.<br>
  I know for a fact that this is possible because Bjarne Stroustrup<br>
  uses this in his book "The C++ programming language"<br>
  (page 293,for example the String and Srep classes).</p>
  
  <p>So this is my minimal piece of code that causes problems</p>
  
  <pre><code>class A{
  struct B; // forward declaration
  B* c;
  A() { c-&gt;i; }
  };
  
  struct A::B { 
  /* 
   * we define struct B like this becuase it
   * was first declared in the namespace A
   */
  int i;
  };
  
  int main() {
  }
  </code></pre>
  
  <p>This code gives the following compilation errors in g++ :</p>
  
  <pre><code>tst.cpp: In constructor ‘A::A()’:
  tst.cpp:5: error: invalid use of undefined type ‘struct A::B’
  tst.cpp:3: error: forward declaration of ‘struct A::B’
  </code></pre>
  
  <p>I tried to look at the C++ Faq and the closeset I got was <a href="http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.12" rel="nofollow noreferrer">here</a> and <a href="http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.13" rel="nofollow noreferrer">here</a> but<br>
  those don't apply to my situation.<br>
  I also <a href="https://stackoverflow.com/questions/237064/c-nested-classes-driving-me-crazy">read this</a> from here but it's not solving my problem.</p>
  
  <p>Both gcc and MSVC 2005 give compiler errors on this</p>