Topic: Is this a dependent name that needs typename?
Author: Jonathan Biggar <jon@floorboard.com>
Date: 1999/03/10 Raw View
In the following:
#include <set>
typename<class T>
class C {
public:
typedef set<T> Set;
typedef Set::iterator Iterator; // is this wrong?
typedef typename Set::iterator Iterator2; // is this right?
};
isn't Set::iterator a dependent name which requires the use of typename,
since it is the same as set<T>::iterator?
Sun C++ 5.0 accepts this without using typename.
--
Jon Biggar
Floorboard Software
jon@floorboard.com
jon@biggar.org
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Stephen.Clamage@Eng.Sun.COM (Steve Clamage)
Date: 1999/03/12 Raw View
Jonathan Biggar <jon@floorboard.com> writes:
>In the following:
>#include <set>
>typename<class T>
>class C {
>public:
> typedef set<T> Set;
> typedef Set::iterator Iterator; // is this wrong?
> typedef typename Set::iterator Iterator2; // is this right?
>};
>isn't Set::iterator a dependent name which requires the use of typename,
>since it is the same as set<T>::iterator?
Yes. In fact, you need typename on the first typedef as well.
>Sun C++ 5.0 accepts this without using typename.
As explained in the documentation that comes with the compiler,
Sun C++ 5.0 recognizes the keyword "typename" but does not
enforce its use.
Speaking more generally:
The purpose of adding typename to the standard was only to allow a
compiler to diagnose some errors in a template definition without
needing to wait for an instantiation. (Without knowing which names
are types, the compiler cannot begin to parse a template definition.)
Typename does not address any template correctness or ambiguity issue,
since a compiler can choose to wait until instantiation time
before detecting any errors. At instantiation time, the meaning
of every declared name is known.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]