Declaration works when I declare an iterator like this:
map<string,int>::iterator it, temp;
Why doesn't the following work too?
map<string,int>temp, ::iterator it;
error: expected initializer before 'it'
Why is this causing an error?
Declaration works when I declare an iterator like this:
map<string,int>::iterator it, temp;
Why doesn't the following work too?
map<string,int>temp, ::iterator it;
error: expected initializer before 'it'
Why is this causing an error?
In the first case you are creating two iterators for the stl map. In the second case you are creating stl maps and c++ expects no space in the identifier and identifier should not start with ":" symbol (rules of c++ lang).
iterator
is a member type inside std::map
container, to have a variable of this type you need to use the proper syntax, map<string,int>temp, ::iterator it;
is simply wrong as complained by the compiler.
map<string,int>::iterator
is a type, ::iterator
is ill formed.