learning policy classes

E

er

hi,

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;
public:
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 Impl2> class A;
template<class Impl1,class Impl2> class B:public Impl1,Impl2{};
and either of Impl1 and Impl2 has a constructor which takes arbitrary
arguments.

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top