title: C++ Passing a derived class as a base class template parameter
body: <p>I'm having trouble passing a class <code>DerivedObject</code> (part of class <code>DerivedClass</code> derived from template class <code>BaseClass</code>) derived from <code>BaseObject</code> (part of template class <code>BaseClass</code>) as a template argument to template class <code>BaseClass</code>.</p>
  
  <p>This way, both Base and Derived classes have the access to the object pool, that can contain derived objects. This sounds a bit confusing, so here is the example:</p>
  
  <pre><code>template &lt;class TDerivedClass, class TDerivedObject&gt;
  class BaseClass
  {
  protected:
      class BaseObject
      {
          // Class implementation
      }
      void foo() 
      { 
          static_cast&lt;TDerivedClass*&gt;(this)-&gt;foo(); 
      }
      std::vector&lt;TDerivedObject*&gt; m_objectPool;
  };
  </code></pre>
  
  <p>The above is the base class implementation.</p>
  
  <pre><code>error C2065: 'DerivedObject' undeclared identifier
  </code></pre>
  
  <p>The above error is cause by the first line of the class definition bellow:</p>
  
  <pre><code>class DerivedClass : public BaseClass&lt;DerivedClass, DerivedClass::DerivedObject&gt;
  {
  protected:
      class DerivedObject : public BaseObject
      {
          // Class implementation
      }
      void foo()
      {
          // Method implementation
      }
  };
  </code></pre>
  
  <p>Is there a way to do this? If not, is there a better solution that would give me the same / similar functionality?</p>