Re: Help with Template-Template and Mixin Polymorphism
On 8/9/07 10:37 AM, in article
1186671429.567087.217270@l70g2000hse.googlegroups.com, "TimeHorse"
<darklord@timehorse.com> wrote:
Hello,
I am trying to create a mixin class heirarchy as follows:
template <class E, class Y>
struct Z { };
template <template <class, class> class X, class Y>
struct A
{
typedef typename X G; // Problem
typedef typename X<A *, Y> F;
A(void) { }
virtual ~A(void) { }
};
template <class Y>
struct B : public virtual A<Z, Y>
{
B(void) { }
virtual ~B(void) { }
};
template <class Y, template <class> class P = B>
struct C :
public virtual A<P<Y>::G, Y>, // Problem
private P<Y>
{
C(void) { }
virtual ~C(void) { }
};
int main(/* int argc, char ** argv */void)
{
C<int> c;
return 0;
}
Personally, I would consider ways of simplifying this set of templates. And
if I understood them, I would offer some suggestions. But at least I was
able to find a solution to your problem (I think):
template <class E, class Y>
struct Z {};
template <template <class, class> class X, class Y>
struct A
{
A() {}
virtual ~A() {}
typedef X<A *, Y> F;
};
template <class Y>
struct B : public virtual A<Z,Y>
{
B() {}
virtual ~B() {}
typedef A<Z,Y> base_class;
};
// have C inherit from the same class that P<Y> does
template <class Y, template <class> class P = B>
struct C : public virtual P<Y>::base_class,
private P<Y>
{
C() {}
virtual ~C() {}
};
int main()
{
C<int> c;
}
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]