-3

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?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Ali Akber
  • 3,670
  • 3
  • 26
  • 40

2 Answers2

1

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).

gman
  • 1,242
  • 2
  • 16
  • 29
1

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.

P0W
  • 46,614
  • 9
  • 72
  • 119