Re: A Newbie Question about template template template

Discussion in 'C++' started by Chris Theis, Jul 22, 2003.

  1. Chris Theis

    Chris Theis Guest

    "DarkSpy" <> wrote in message
    news:...
    > #include <vector>
    > using namespace std;
    >
    > template <template <typename T> class B1,
    > template <template<typename T> class B2> class B3> class CX
    > {};
    > main()
    > {
    > CX<vector, vector<vector> > c;


    Just to make sure - what you want to achieve is a template class with 2
    template parameters like this code should indicate?

    > }
    >

    [SNIP]

    > can i make 2 arguments with template class ?

    Yes.

    > is this code correct ?


    No!

    If you want to have a class with 2 template parameters you have to write:

    template< typename T1, typename T2 >
    class CX
    {
    };

    This means you can do the following for example:

    int main()
    {
    CX<vector<int>, vector<vector<int> > > c;

    return true;
    }

    HTH
    Chris
     
    Chris Theis, Jul 22, 2003
    #1
    1. Advertisements

  2. Chris Theis

    DarkSpy Guest

    thanx Chris

    maybe my question is not explicitly.

    i means:

    can i wrote template arguments in template template argument like my code.

    template <template <template <typename> class T> class U>
    class CX {};
    ......

    how many nested template arguments in template template argument ?

    thank you.

    "Chris Theis" <> wrote in message news:<bfjabs$fk2$>...
    > "DarkSpy" <> wrote in message
    > news:...
    > > #include <vector>
    > > using namespace std;
    > >
    > > template <template <typename T> class B1,
    > > template <template<typename T> class B2> class B3> class CX
    > > {};
    > > main()
    > > {
    > > CX<vector, vector<vector> > c;

    >
    > Just to make sure - what you want to achieve is a template class with 2
    > template parameters like this code should indicate?
    >
    > > }
    > >

    > [SNIP]
    >
    > > can i make 2 arguments with template class ?

    > Yes.
    >
    > > is this code correct ?

    >
    > No!
    >
    > If you want to have a class with 2 template parameters you have to write:
    >
    > template< typename T1, typename T2 >
    > class CX
    > {
    > };
    >
    > This means you can do the following for example:
    >
    > int main()
    > {
    > CX<vector<int>, vector<vector<int> > > c;
    >
    > return true;
    > }
    >
    > HTH
    > Chris
     
    DarkSpy, Jul 23, 2003
    #2
    1. Advertisements

  3. Chris Theis

    Chris Theis Guest

    "DarkSpy" <> wrote in message
    news:...
    > thanx Chris
    >
    > maybe my question is not explicitly.
    >
    > i means:
    >
    > can i wrote template arguments in template template argument like my code.
    >
    > template <template <template <typename> class T> class U>
    > class CX {};
    > .....
    >
    > how many nested template arguments in template template argument ?
    >
    > thank you.
    >


    You can use template arguments in template template declarations. I tried
    this up to 5 levels of complexity though the question that arises is if it
    makes sense! Furthermore you should be aware that not all compilers support
    this feature yet!

    HTH
    Chris
     
    Chris Theis, Jul 24, 2003
    #3
    1. Advertisements

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. sieg1974
    Replies:
    2
    Views:
    349
    velthuijsen
    Apr 22, 2004
  2. marcus

    Newbie: template question

    marcus, Feb 12, 2005, in forum: C++
    Replies:
    4
    Views:
    604
    marcus
    Feb 15, 2005
  3. Dilip
    Replies:
    5
    Views:
    412
    Fei Liu
    Apr 21, 2006
  4. Replies:
    1
    Views:
    2,269
    Gianni Mariani
    Jun 8, 2007
  5. Replies:
    2
    Views:
    357
  6. Peng Yu
    Replies:
    3
    Views:
    964
    Thomas J. Gritzan
    Oct 26, 2008
  7. Jerry C.
    Replies:
    8
    Views:
    543
    Uri Guttman
    Nov 23, 2003
  8. Dennis Lee Bieber

    Re: Newbie to python. Very newbie question

    Dennis Lee Bieber, Apr 7, 2013, in forum: Python
    Replies:
    1
    Views:
    146
    Miki Tebeka
    Apr 8, 2013
Loading...