Re: typename
* saneman:
In a template class I have:
typedef std::list<V,A> list;
typedef list::iterator iterator;
but this gives a compile error. If I replace the second line with:
typedef typename list::iterator iterator;
it works. But why? I have read that typename should be used when an
expression depends on template parameters.
If that is the case why is it not necessary to use typename in the first
line?
In the first line std::list<V,A> will be a concrete a concrete class
when the template parameters are filled in, and thus known to be a type.
It's unknown exactly /which/ concrete class std::list<V,A> will be, but
it's known that it will be some concrete class.
The second line is equivalent to
typedef std::list<V,A>::iterator iterator;
Here, due to the lack of knowledge of exactly which concrete class
std::list<V,A> will be, e.g. due to specialization of the std::list
template, it's unknown whether there will be an 'iterator' member and if
so, what kind of member it will be -- type, variable, function,
template, what?
You have to say what you assume and require that it will be.
In effect, by adding the word 'typename' you make a specialization of
std::list that doesn't have a type 'iterator', invalid.
Cheers & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?