:: is the scope resolution operator that expects a type name or namespace name on the left. It does not accept object names on the left. Solving this is likely to be overly complex in the language.
In fact, if someone allowed something like this, probably this function could be bound to an operator . , since the operator . - the one used with objects on the LHS
for (mymap.iterator it = mymap.begin(); it != mymap.end(); ++it)
But it would still unnecessarily complicate things.
In the future, C ++ is standard, something like this will be possible thanks to decltype keyword
for (decltype(mymap)::iterator it = mymap.begin(); it != mymap.end(); ++it)
PS According to the Wikipedia article on decltype , its presence in skilled expired was a matter. If I understood correctly, this use was eventually voted.
PPS Also, as @Asha notes in the comments, in the future C ++ you will be able to avoid type naming at all
for (auto it = mymap.begin(); it != mymap.end(); ++it)
AnT
source share