C
Cyron
Hello friends,
Recently I have begun exploring the features that the STL map
collection provides. While learning how it worked, I encountered a
result that confused me. Up until now, I had always been under the
impression that if I had a pointer variable, p which contained the
member "first", I could access this member variable either by:
(*p).first OR p->first . That is, in general I thought p->x was just
shorthand for (*p).x ?
The particular example I was working with was with printing an item
from a map:
map<string,int> m ;
m.insert( make_pair( string( "test" ), false ) ) ;
map<string,int>::const_iterator it ;
for ( it = m.begin() ; it != m.end() ; it++ ) {
cout << it->first ; // THIS DOES NOT WORK
cout << (*it).first ; // This does work
}
Can anyone render an explanation to put my mind at ease?
Thanks in advance,
Mike
Recently I have begun exploring the features that the STL map
collection provides. While learning how it worked, I encountered a
result that confused me. Up until now, I had always been under the
impression that if I had a pointer variable, p which contained the
member "first", I could access this member variable either by:
(*p).first OR p->first . That is, in general I thought p->x was just
shorthand for (*p).x ?
The particular example I was working with was with printing an item
from a map:
map<string,int> m ;
m.insert( make_pair( string( "test" ), false ) ) ;
map<string,int>::const_iterator it ;
for ( it = m.begin() ; it != m.end() ; it++ ) {
cout << it->first ; // THIS DOES NOT WORK
cout << (*it).first ; // This does work
}
Can anyone render an explanation to put my mind at ease?
Thanks in advance,
Mike