Typedefing a typename

The typename keyword does not automatically create a typedef. A line which reads:
typename Seq::iterator It;

causes a variable to be declared of type Seq::iterator. If you mean to make a typedef, you must say:
typedef typename Seq::iterator It;

Using typename instead of class
With the introduction of the typename keyword, you now have the option of using typename instead of class in the template argument list of a template definition. This may produce code which is clearer:

You?ll probably see a great deal of code which does not use typename in this fashion, since the keyword was added to the language a relatively long time after templates were introduced.

Share
Tweet
Share
Pin