using templates in templates

Discussion in 'C++' started by John Harrison, Jul 31, 2003.

  1. "Torsten Curdt" <> wrote in message
    news:bgan9a$mi77v$-berlin.de...
    > template<class TYPE, class ELEMENT>
    > class MyClass : public TYPE<ELEMENT,ELEMENT>
    > {
    > };
    >
    > This does not seem to work - but why?


    Because it makes my head hurt?

    john
    John Harrison, Jul 31, 2003
    #1
    1. Advertising

  2. template<class TYPE, class ELEMENT>
    class MyClass : public TYPE<ELEMENT,ELEMENT>
    {
    };

    This does not seem to work - but why?
    --
    Torsten
    Torsten Curdt, Jul 31, 2003
    #2
    1. Advertising

  3. "Torsten Curdt" <> wrote in message
    news:bgan9a$mi77v$-berlin.de...
    > template<class TYPE, class ELEMENT>
    > class MyClass : public TYPE<ELEMENT,ELEMENT>
    > {
    > };
    >
    > This does not seem to work - but why?


    You are using the wrong syntax. You need to specify that you want TYPE
    to be a template class that takes two typename-parameters (or
    class-parameters, it is the same thing), like this:

    template <template <class T, class U> class TYPE, class ELEMENT>
    class MyClass : public TYPE <ELEMENT,ELEMENT>
    {
    };

    hth
    --
    jb

    (replace y with x if you want to reply by e-mail)
    Jakob Bieling, Jul 31, 2003
    #3
  4. John Harrison

    Greg P. Guest

    "Jakob Bieling" <> wrote in message
    news:bgao8s$5o5$07$-online.com...
    > "Torsten Curdt" <> wrote in message
    > news:bgan9a$mi77v$-berlin.de...
    > template <template <class T, class U> class TYPE, class ELEMENT>
    > class MyClass : public TYPE <ELEMENT,ELEMENT>

    God what a headache! Generalizing the generalized! =/
    Greg P., Jul 31, 2003
    #4
  5. "Torsten Curdt" <> wrote in message
    news:bgap6o$mfumj$-berlin.de...
    > > You are using the wrong syntax. You need to specify that you want

    TYPE
    > > to be a template class that takes two typename-parameters (or
    > > class-parameters, it is the same thing), like this:
    > >
    > > template <template <class T, class U> class TYPE, class ELEMENT>
    > > class MyClass : public TYPE <ELEMENT,ELEMENT>
    > > {
    > > };

    >
    > ok, but then I would need to use the template like this, right?
    >
    > MyClass< Base<A,B> >


    No, because a) Base<A,B> is no template class anymore (it is treated
    like a regular class type) and b) MyClass takes two template parameters, but
    you pass only one.

    > but because usually A == B I'd like to write
    >
    > MyClass< Base, A >


    If 'Base' is a template class and 'A' is a typename, then this is how
    you would write it, yes.

    > but now I understand: "Base" is not a regular but a class
    > template - that's why, right?
    >
    > Any way to work around this?


    To work around what? You wrote, you would like to write "MyClass <Base,
    A>" (and I assume 'Base' is a template class and 'A' is a typename), which
    is exactly how you are supposed to write it.

    hth
    --
    jb

    (replace y with x if you want to reply by e-mail)
    Jakob Bieling, Jul 31, 2003
    #5
  6. > To work around what? You wrote, you would like to write "MyClass <Base,
    > A>" (and I assume 'Base' is a template class and 'A' is a typename), which
    > is exactly how you are supposed to write it.


    ok, thanks

    too bad but the compiler doesn't like nested templates :(
    --
    Torsten
    Torsten Curdt, Jul 31, 2003
    #6
  7. Torsten Curdt wrote:

    >> To work around what? You wrote, you would like to write "MyClass
    >> <Base,
    >> A>" (and I assume 'Base' is a template class and 'A' is a typename),
    >> which is exactly how you are supposed to write it.

    >
    > ok, thanks
    >
    > too bad but the compiler doesn't like nested templates :(

    gcc does

    > --
    > Torsten
    Tobias Langner, Jul 31, 2003
    #7
  8. "Torsten Curdt" <> wrote in message
    news:bgatdm$mkrij$-berlin.de...
    > > To work around what? You wrote, you would like to write "MyClass

    <Base,
    > > A>" (and I assume 'Base' is a template class and 'A' is a typename),

    which
    > > is exactly how you are supposed to write it.

    >
    > ok, thanks
    >
    > too bad but the compiler doesn't like nested templates :(



    Which one are you using? VC++ 7.1 supports them.
    --
    jb

    (replace y with x if you want to reply by e-mail)
    Jakob Bieling, Jul 31, 2003
    #8
  9. Jakob Bieling wrote:
    > "Torsten Curdt" <> wrote in message
    > news:bgatdm$mkrij$-berlin.de...
    >
    >>> To work around what? You wrote, you would like to write "MyClass

    >
    > <Base,
    >
    >>>A>" (and I assume 'Base' is a template class and 'A' is a typename),

    >
    > which
    >
    >>>is exactly how you are supposed to write it.

    >>
    >>ok, thanks
    >>
    >>too bad but the compiler doesn't like nested templates :(

    >
    >
    >
    > Which one are you using? VC++ 7.1 supports them.


    eVC++ 4

    In the help there is even an example of nested templates
    but the compilers complains anyway :-/
    --
    Torsten
    Torsten Curdt, Jul 31, 2003
    #9
    1. Advertising

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. Fred
    Replies:
    1
    Views:
    580
    Neredbojias
    Sep 26, 2005
  2. JKop
    Replies:
    3
    Views:
    453
  3. Tom McCallum

    Templates within templates

    Tom McCallum, Aug 4, 2004, in forum: C++
    Replies:
    2
    Views:
    357
    tom_usenet
    Aug 4, 2004
  4. Audrey Pratt
    Replies:
    0
    Views:
    3,239
    Audrey Pratt
    Dec 14, 2005
  5. recover
    Replies:
    2
    Views:
    788
    recover
    Jul 25, 2006
Loading...

Share This Page