Iterator over a map of generic vectors.
Eric Lance
eric.lance@gmail.com
Fri Sep 8 22:28:00 GMT 2006
Hi all,
I'm trying to figure out if this is a bug or "feature". In a generic
function, I want to declare an iterator over a map whose values are
generic vectors. However, I get a syntax error whenever I try to
declare this particular kind of iterator. The code snippet below
should illustrate what I mean better:
template<typename T>
void func()
{
map< int, vector<T> > m; //we want an iterator over m.
map< int, vector<T> >::iterator i; //this doesn't compile
map< int, vector<int> >::iterator k; //but this does
}
On GCC 4.1.0 (Suse) and GCC 3.4.4 (FreeBSD) it throws the following
syntax error:
Test.cpp: In function 'void func()':
Test.cpp:16: error: expected `;' before 'i'
The code snippet will compile cleanly on MS visual studio. It also
seems illogical that I can declare map "m", but it is illegal to
declare the iterator " i". So, is this a "feature" or a bug?
I'm not subscribed to the list, so please CC me in on any replies.
Thanks,
Eric
PS As a workaround, I changed the declaration to the following, which
seems to work:
typeof(m.iterator) i=m.begin();
More information about the Gcc-help
mailing list