title: In C++, is it possible to forward declare a class as inheriting from another class?
body: <p>I know that I can do:</p>
  
  <pre><code>class Foo;
  </code></pre>
  
  <p>but can I forward declare a class as inheriting from another, like:</p>
  
  <pre><code>class Bar {};
  
  class Foo: public Bar;
  </code></pre>
  
  <hr>
  
  <p>An example use case would be co-variant reference return types.</p>
  
  <pre><code>// somewhere.h
  class RA {}
  class RB : public RA {}
  </code></pre>
  
  <p>... and then in another header that doesn't include somewhere.h</p>
  
  <pre><code>// other.h
  class RA;
  
  class A {
   public:
    virtual RA* Foo();  // this only needs the forward deceleration
  }
  
  class RB : public RA; // invalid but...
  
  class B {
   public:
    virtual RB* Foo();  // 
  }
  </code></pre>
  
  <p>The only information the compiler <em>should</em> need to process the declaration of <code>RB* B:Foo()</code> is that <code>RB</code> has <code>RA</code> as a public base class. Now clearly you would need somewhere.h if you intend to do any sort of dereferencing of the return values from <code>Foo</code>. However, if some clients never calls <code>Foo</code>, then there is no reason for them to include somewhere.h which might significantly speed compilation.</p>