K
kjackson.ken
I have code such as the following:
map<int, string> stringMap;
stringMap.insert(map<int,string>::value_type(1, "hello"));
map<int, string>::iterator iter;
iter = stringMap.find(1);
iter->second = "goodbye";
I know after experimentation that when I use the iterator to change
the value of second, that I am actually manipulating the underlying
object. So the next time I call find, it will reference "goodbye".
My question is, how does it accomplish this? Is this a hard and fast
rule? Can I assume that the find member function for maps will not
copy-by-value and always allow me to manipulate the underlying object
through the interator, even if it were things like pointers, etc?
Thanks,
Ken Jackson
map<int, string> stringMap;
stringMap.insert(map<int,string>::value_type(1, "hello"));
map<int, string>::iterator iter;
iter = stringMap.find(1);
iter->second = "goodbye";
I know after experimentation that when I use the iterator to change
the value of second, that I am actually manipulating the underlying
object. So the next time I call find, it will reference "goodbye".
My question is, how does it accomplish this? Is this a hard and fast
rule? Can I assume that the find member function for maps will not
copy-by-value and always allow me to manipulate the underlying object
through the interator, even if it were things like pointers, etc?
Thanks,
Ken Jackson