Is it OK to pass to function a reference to the value of map element, and to modify it there?
foo(string & s)
{
s = "xyz";
}
map<int, string> m;
m[1] = "abc";
foo(m[1]); // <-- Is it ok? Will m[1] be "xyz" after this call?
Thank you.
A word of advice: You might want to pass it as a pointer rather than a reference. I do that to make it more obvious to the casual reader that it will be changed.
It's all about communicating clearly with the next guy comming down the pike, who has to maintain this code.
But other than that, yeah, it's completely legal code!