a template question

Discussion in 'C++' started by Tony Johansson, Aug 15, 2005.

  1. Hello Experts!

    I reading a book called programming with design pattern revealed
    by Tomasz Muldner and here I read something that I don't understand
    completely.

    It says:
    "Type parameterization makes it possible to combine two representation.
    For example, the class Stack<T> and the class List<T> can be combined in one
    step to
    create a stack of lists of type T:"
    Stack<List<T> >

    Now to my question
    When we have the declaration with the template in the beginning of a class
    definition in this way
    template<class T>
    what type is T when we have this expression Stack<List<T> > as above.
    List<T> in not a type so how can it be possible to write a expression like
    this Stack<List<T> > then
    I do know if you write Stack<int> si; or Stack<Student> ss what it means.

    Many thanks

    //Tony
     
    Tony Johansson, Aug 15, 2005
    #1
    1. Advertising

  2. Tony Johansson wrote:
    > I reading a book called programming with design pattern revealed
    > by Tomasz Muldner and here I read something that I don't understand
    > completely.
    >
    > It says:
    > "Type parameterization makes it possible to combine two representation.
    > For example, the class Stack<T> and the class List<T> can be combined in one
    > step to
    > create a stack of lists of type T:"
    > Stack<List<T> >
    >
    > Now to my question
    > When we have the declaration with the template in the beginning of a class
    > definition in this way
    > template<class T>
    > what type is T when we have this expression Stack<List<T> > as above.


    'Stack<List<T> >' is not an expression, unless it's inside another
    template, like

    template<class T> void foo(T t) {
    Stack<List<T> > blah;
    ...
    }

    here, in the declaration of 'blah', the 'T' is the same as the one for
    which 'foo' was instantiated.

    > List<T> in not a type so how can it be possible to write a expression like
    > this Stack<List<T> > then
    > I do know if you write Stack<int> si; or Stack<Student> ss what it means.


    By the same token you can write Stack<List<Student> > , can't you? I
    believe that's what the author meant. Of course, you have taken the words
    out of context (and I don't have the book) so it's difficult to say for
    sure what the author may have meant...

    V
     
    Victor Bazarov, Aug 15, 2005
    #2
    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. Chris Theis
    Replies:
    2
    Views:
    486
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    549
    tom_usenet
    Jul 24, 2003
  3. Replies:
    1
    Views:
    2,129
    Gianni Mariani
    Jun 8, 2007
  4. Peng Yu
    Replies:
    3
    Views:
    791
    Thomas J. Gritzan
    Oct 26, 2008
  5. nguillot
    Replies:
    5
    Views:
    539
Loading...

Share This Page