Help with Template-Template and Mixin Polymorphism

Discussion in 'C++' started by TimeHorse, Aug 9, 2007.

  1. TimeHorse

    TimeHorse Guest

    Re: Cross-posted from the moderated group (but this version has
    spelling fixes).

    Hello,

    I am trying to create a mixin class hierarchy 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;
    }

    In this, struct Z is a utility template; there may be many definitions
    for struct Z. struct A is a virtual base class used to set up
    polymorphism for the derived mixin classes. B is an implementation of
    a Policy Class. Among other things, B is meant to decide which
    template to use for the X parameter in A's template (in this case it
    chooses template struct Z). C puts all the mixin policies together.
    Here, only one policy is demonstrated, denoted P, which defaults to
    B. In each example, Y is a value decided at compile time at the point
    of instantiation. In this case, it is instantiated with int. The
    problem I am obviously having is that: when B sets X in A through its
    base class definition, C has no way of retrieving that binding from P
    in order to set the same value for its virtual base A allowing the two
    virtual bases to match and act virtually.

    In A, the typedef of G is invalid because X is not a type but a
    templated type and there is no typedef equivalent to bind a template
    parameter (X) to a name (G) so that derived classes can access it.

    Secondly, there is no way in C's base classes to specify "A with
    template parameters G from P<Y> and Y", where G is assumed to be a
    name bound to A that refers to its template parameter X. Again, G
    should be defined in B's base class A, which B sets to the value Z.

    Does this make sense? Is it possible to do this? Any alternative
    suggestions?? Thank!

    Jeffrey.
    TimeHorse, Aug 9, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krivenok Dmitry
    Replies:
    13
    Views:
    1,390
    Axter
    Jun 1, 2006
  2. Florian Gross
    Replies:
    12
    Views:
    218
    Florian GroƟ
    Apr 4, 2005
  3. Replies:
    13
    Views:
    331
    Robert Klemme
    Nov 7, 2005
  4. Manuel Kasten
    Replies:
    5
    Views:
    72
    Manuel Kasten
    Nov 10, 2005
  5. Vellingiri Arul

    difference between inheritance and mixin

    Vellingiri Arul, Sep 26, 2007, in forum: Ruby
    Replies:
    6
    Views:
    135
    Robert Dober
    Sep 26, 2007
Loading...

Share This Page