Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: template cl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 43661 of 48417
Post > Topic >>

Re: template class

by er <erwann.rogard@[EMAIL PROTECTED] > Mar 4, 2008 at 07:52 AM

On Mar 4, 10:20 am, gnuyuva <gnuy...@[EMAIL PROTECTED]
> wrote:
> On Mar 4, 6:24 pm, er <erwann.rog...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > Hi all,
>
> > template<class P,template<class> class TC> class A{
> >    typedef TC<P> tc_type;
> >    /*...*/
>
> > };
>
> > template<class P1,class P2 > class B{/*...*/};
>
> > If I want to use B as a parameter in A, for each P2=p2,  I need
>
> > template<class P1>
> > class B_p2: public B<P1,p2>{
> >  typedef B<P1,p2> parent_type;
> >  /* may have to write constructors such as B_p2(...):parent_type(...)
> > {} */
>
> > };
>
> > I can use it as:
>
> > A<P,B_p2> a_p_t2;
>
> > Is there a better way/more generic way than writing a new template
> > class for each P2?
>
> How about this:
>
> template <typename P1>
> struct BindP2toB
> {
>    typedef p2 P2;
>    typedef B<P1, P2> base_type;
>
> };
>
> template <typename P1, template<typename> class TC >
> class A
> {
>    typedef TC<P1>::base_type tc_type;
>
> };
>
> So, you can use it like:
> A<P1, BindP2toB> a_p_t2;
>
> Make sure that you get all 'base_type's defined for each class used
> inside A.

Great, thanks!
 




 3 Posts in Topic:
template class
er <erwann.rogard@[EMA  2008-03-04 05:24:48 
Re: template class
gnuyuva <gnuyuva@[EMAI  2008-03-04 07:20:39 
Re: template class
er <erwann.rogard@[EMA  2008-03-04 07:52:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 10:22:51 CST 2008.