template class inheritance syntax
<p>My intention is to have some base class <code>CBaseClass</code> that, amongst other things, serves as a container to some members of type <code>CBaseMember</code>; then to derive a <code>CDerivedClass : public CBaseClass</code> that holds <code>CDerivedMember : public CBaseMember</code>.</p>

<p>I can't use a pointer to <code>CBaseMember</code> and initialize it with a <code>CDerivedMember</code> object in <code>CDerivedClass</code> because it's a multiple inheritance situation, <code>CDerivedMember</code> has an additional interface (a pure abstract base class) that is irrelevant to <code>CBaseClass</code> implementation but needs to be visible to <code>CDerivedClass</code>. Lots of dirty casting is something that I would very much like to avoid.</p>

<p>My solution to this problem was to make <code>CBaseClass</code> a template, like this:</p>

<pre><code>//declaration
template &lt;class Member&gt;
CBaseClass
{
protected:
    virtual void GenericMethod();
    virtual void VirtualMethod() = 0;

    Member* member;
};

//definition
template &lt;class Member&gt;
void CBaseClass&lt;Member&gt;::GenericMethod()
{
    member-&gt;SomeMemberMethod();
}
</code></pre>

<p>and then to inherit <code>CDerivedClass</code> from it, like this:</p>

<pre><code>//declaration
CDerivedClass : public CBaseClass&lt;CDerivedMember&gt;
{
protected:
    virtual void VirtualMethod();
};

//definition
void CDerivedClass::VirtualMethod()
{
    member-&gt;SomeDerivedMethod();
}
</code></pre>

<p>Predictably, this doesn't work (<code>CBaseClass&lt;CDerivedMember&gt;::GenericMethod()</code> is unresolved, for obivious reasons), but unfortunatly I don't know how to change my code to mean what I intend for it to mean.</p>

<p>Can anyone please explain how those things are done properly - or suggest another solution for my problem?</p>

<p>Thanks!</p>
