gcc-3.4 requires 'typename' to use map in a template?

Dan Kegel dkegel@ixiacom.com
Fri Oct 3 00:39:00 GMT 2003


Dan Kegel wrote:
> #include <map>
> 
> template <typename T>
> class myclass {
>         typedef std::map<T, unsigned int> mymap;
> public:
>         void mymethod() {
>             typename mymap::iterator myvar;
>             myvar = 0;
>         }
> };
> 
> So is gcc-3.4-20031001 right to require typename here, or is this a bug?

The local language lawyer says yep, gcc-3.4 could be right;
since mymap depends on T, it needs the 'typename'.
But shoot, you'd *think* a typedef would be enough of a clue!
Man, is this nonintuitive...

I guess I'll run out and buy that book _C++ Templates: The Complete Guide_
mentioned in the previous post,
http://gcc.gnu.org/ml/gcc/2003-10/msg00082.html
- Dan



More information about the Gcc mailing list