Re: Help with Template-Template and Mixin Polymorphism
On Aug 9, 4:12 pm, Greg Herlihy <gre...@pacbell.net> wrote:
// 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() {}
};
I'm sorry Greg. This solution will in fact not work for me. I wrote
a simplified example of a Polymorphic Policy Paradigm adapted from
Modern C++ Design by Andrei Alexandrescu but my situation is more
complicated; too complicated to spell out completely. However, the
reason this won't work is simple I think to understand. Again. assume
I have 2 policies in the template list for C, called P and Q, P as
before. Let's say Q does not need to override any template parameters
in A like P (B) does, but it does need to override a different set of
virtual functions in A independant of those defined in B. For
example, let's say A::bar is another pure virtual function that Policy
Q is supposed to handle. Since Q must implement bar, Q also must be
derived from A, only for Q, he will not know what to pass for A's X
template parameter. So he parameterizes X as well. Now, in C, she
has to supply X to Q and A. We solved A by defining P<Y>::base_class,
but we still don't have a way to pass the template-template parameter
to Q and thus his virtual reference to A.
Of course, I could make all the policies take one parameter
representing the correct instantiation of the base class A from which
they should inherit, but it still doesn't solve the P1::X, P2::W
problem from my last post and something makes me nervious about having
a single policy define the base for all other policies like that,
especially when you end up with all other policies taking a single
template parameter of class type representing their public virtual
base class. It can be done, but the symmetry seems off. Thanks
though!
Jeffrey.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]