By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

learning policy classes

P: n/a

i'm trying to understand A) policy classes and see if they meet my
needs. the book "C++ templates" has something similar called B)
"bridge pattern implemented with templates". would it be fair to
characterize them like this?

template<class Impl>//Impl has to have void op();
class A{//bridge pattern
Impl impl;
void op(){impl.op();};
template<class Impl>
class B: public Impl{};//Impl used as a policy

what i'm really leading to is the issue of having more than one
template parameter, say
template<class Impl1,class Impl2class A;
template<class Impl1,class Impl2class B:public Impl1,Impl2{};
and either of Impl1 and Impl2 has a constructor which takes arbitrary

i think that's not a problem for A (?):
A<Impl1,Impl2>::A(const Impl1& i1,const Impl2 i2):impl1(i1),impl2(i2)

i guess i do the same for B ? or is this reasonable?
template<class In1, class Impl1,class In2, class Impl2//must satisfy
Impli::Impli(Ini), i=1,2
class B: public Impl1,public Impl2{};
B<In1,Impl1,In2,Impl2>::B:Impl1(In1),Impl2(In2){} ;

this means that for each Impl1 with constructor Impl1::Impl1(Args...),
i have 1) to create a class In1::In1(Args...) and overload as
Impl1::Impl1(In1). i haven't seen any examples like this so i'm
wondering if policies are suitable in this context. if they are, is
there a way that the host (B) can deduce In1, In2, rather than make
them explicit?

Oct 22 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.