Answer the question
In order to leave comments, you need to log in
What does typename mean?
Good evening! There is a task to make an iterator for the stack (yes, I am aware that there are other containers =) ) I spied on the guys how to do this, but I can’t understand what it means:
typedef typename std::stack<T>::container_type::iterator iterator;
template<typename T>
std::stack<T>::container_type::iterator
Answer the question
In order to leave comments, you need to log in
1. typename
in this case, the compiler is needed only as a hint from the developer that the subsequent identifier (ie std::stack<T>::container_type::iterator
) is really a type name. The hint is needed because this typedef is probably also in the template, and we do not yet know what exactly the std::stack template is instantiated into (in this case, we say that container_type "is dependent on a template-parameter" - until we instantiate std ::stack, we won't know).
2. Member-type container_type
is equivalent to the type of the underlying container (because std::stack is an adapter for the stack interface, and not a real container, you choose the real storage container as the second template parameter, by default it is std::deque).
3. Here the std::deque<T>
iterator really is.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question