gcc-3.4 requires 'typename' to use map in a template?
Dan Kegel
dkegel@ixiacom.com
Thu Oct 2 23:56:00 GMT 2003
The following code is rejected by gcc-3.4-20031001, but accepted
by gcc-2.95 and gcc-3.2.3:
#include <map>
template <typename T>
class myclass {
typedef std::map<T, unsigned int> mymap;
public:
void mymethod() {
mymap::iterator myvar;
myvar = 0;
}
};
Command to reproduce:
$ /usr/local/gcc-3.4-20031001/bin/g++ foo2.cc
foo2.cc: In member function `void myclass<T>::mymethod()':
foo2.cc:8: error: expected `;'
foo2.cc:9: error: `myvar' undeclared (first use this function)
Using the typename keyword seems to be a workaround, as
gcc-3.4-20031001 accepts the following code without complaint:
#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?
- Dan
More information about the Gcc
mailing list