a template question

T

Tony Johansson

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
 
V

Victor Bazarov

Tony said:
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top