title: C++ Returning a child class from within a parent class
body: <p>So I have two classes like this</p>
  
  <pre><code>#pragma once
  #include "B.h"
  class A {
  public:
      B getB() {}
  };
  </code></pre>
  
  <p>and</p>
  
  <pre><code>#pragma once
  #include "A.h"
  class B : public A {
  
  };
  </code></pre>
  
  <p>Error: 'A' base class undefined.</p>
  
  <p>Both need to be declared before the other one so how do I fix this?</p>
  
  <p>If you reorder the code into one file then it looks like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class B : public A {
  
  };
  class A {
  public:
      B getB() {}
  };
  
  void main() {
      A a;
      B b = a.getB();
      system("pause");
  }
  </code></pre>
  
  <p>But the problem is still there...</p>